sauladam/omnipay-paysafecard-rest

Omnipay支付处理库的Paysafecard(带REST API)网关

0.2.0 2017-05-25 14:20 UTC

This package is auto-updated.

Last update: 2024-09-17 05:47:36 UTC


README

Omnipay PHP支付处理库的Paysafecard驱动程序

Build Status Total Downloads

这是Paysafecard支付网关提供商Paysafecard的非官方Omnipay驱动程序。为了使用它,需要Omnipay框架。

Omnipay是一个与框架无关的多网关支付处理库,适用于PHP 5.3+。此包实现了Omnipay对Paysafecard REST API的支持。

安装

此包通过Composer安装。要安装,只需将其添加到您的composer.json文件中

$ composer require sauladam/omnipay-paysafecard-rest

然后运行Composer来更新您的依赖项

$ composer update

基本用法

此包提供以下网关

  • Paysafecard_Rest

有关一般使用说明,请参阅Omnipay的主要存储库。

设置网关

这很简单,因为API只需要一个API密钥。

require 'vendor/autoload.php';

use Omnipay\Omnipay;

$gateway = Omnipay::create('Paysafecard_Rest');

$gateway->setApiKey('yourApiKey');

// Testmode is on by default, so you want to switch it off for production.
$gateway->setTestMode(false); // default: true

初始化/授权支付

$response = $gateway->authorize([
    'amount' => 0.01,
    'currency' => 'EUR',
    'success_url' => 'http://success.com/{payment_id}',
    'failure_url' => 'http://fail.com/{payment_id}',
    'notification_url' => 'http://notify.com/{payment_id}',
    'customer_id' => 1234,
])->send();

if ($response->isSuccessful()) {
    $paymentId = $response->getPaymentId(); 
    
    // this is the url you should redirect the customer 
    // to or display within an iframe
    $authUrl = $response->authUrl();
} else {
    echo 'Something went wrong: ' . $response->getMessage();
}

授权URL指向一个(安全)页面,客户可以输入他们的Paysafecard PIN码。您可以将客户重定向到该URL或将其嵌入iframe中并显示给他们 - 两者都可以。

客户填写并提交表单后,Paysafecard将他们重定向到您在授权请求中指定的success_url。理想情况下,该URL应包含某种支付标识符或对先前存储的$paymentId的引用(Paysafecard将在URL中的占位符{payment_id}处替换为实际支付ID),因为您现在需要它来检查此交易的状态

检查状态

$response = $gateway->details([
    'payment_id' => $paymentId,
])->send();

现在的状态应该是AUTHORIZED,所以检查它

if($response->getStatus() == 'AUTHORIZED')
{
    // The customer has authorized the payment, we're now ready to capture it.
}

捕获交易

$response = $gateway->capture([
    'payment_id' => $paymentId,
])->send();

if($response->getStatus() == 'SUCCESS') {
    // You have successfully captured the payment, the order is ready to ship.
}

退款

为了使用退款API,您必须明确要求Paysafecard为您启用此端点,否则您将收到“401未授权”响应。

如果您想立即执行退款,只需直接使用带有所有所需数据的refund()函数即可

$response = $gateway->refund([
    'payment_id' => $paymentId,
    'amount' => 12.34,
    'currency' => 'EUR',
    'customer_email' => 'customer@email.com',
    'customer_id' => 1234,
])->send();

if($response->getStatus() == 'SUCCESS') {
    // The amount was successfully refunded.
}

但是,**建议首先验证退款**以“预检查即将到来的退款是否可能成功”,因为**某些条件可能导致退款被拒绝**。

因此,您应该首先使用validateRefund()与相同的数据进行验证,只有在验证通过的情况下才请求退款

$validationResponse = $gateway->validateRefund([
    // same data as above
])->send();

if(! $validationResponse->isSuccessful() || $validationResponse->getStatus() != 'VALIDATION_SUCCESSFUL') {
    // something went wrong...
}

$refundResponse = $gateway->refund([
  'payment_id' => $paymentId,
  'refund_id' => $response->getRefundId(),
])->send();

if($refundResponse->isSuccessful()) {
    echo "The refund was successful and the refund id is " . $refundResponse->getRefundId(); 
}

支持

有关更多使用示例,请参阅此包的测试。还可以查阅Paysafecard API文档以获取更多详细信息。

如果您对Omnipay有任何一般问题,我们建议在Stack Overflow上发布。请确保添加omnipay标签,以便易于找到。

如果您想了解发布公告,讨论项目想法或提出更详细的问题,还有一个邮件列表,您可以订阅。

如果您认为发现了bug,请使用GitHub问题跟踪器进行报告,或者更好的方法是分叉库并提交pull request。