worldstream-labs / omnipay-paysafecard
Omnipay支付处理库的Paysafecard驱动程序
v1.1.0
2020-08-05 10:21 UTC
Requires
- php: ^7.1.0
- ext-json: *
- omnipay/common: ^3.0.1
Requires (Dev)
- omnipay/tests: ^3.1
This package is auto-updated.
Last update: 2024-09-05 19:57:40 UTC
README
Omnipay V3支付库的Paysafecard库
安装
使用composer将库添加到项目的依赖项中 composer require worldstream-labs/omnipay-paysafecard
开发
为开发设置
composer install
使用方法
设置
<?php require 'vendor/autoload.php'; use Omnipay\Omnipay; $gateway = Omnipay::create('Paysafecard'); $gateway->setApiKey('yourApiKey'); // When deploying to production, don't forget to set test mode to false $gateway->setTestMode(false);
授权支付
<?php require 'vendor/autoload.php'; use Omnipay\Omnipay; $gateway = Omnipay::create('Paysafecard'); $gateway->setApiKey('yourApiKey'); $response = $gateway->authorize([ 'amount' => 10.00, 'currency' => 'EUR', 'success_url' => 'https://website/success/{payment_id}', 'failure_url' => 'https://website/failure/{payment_id}', 'notification_url' => 'https://website/notification/{payment_id}', ])->send(); if (!$response->isSuccessful()) { throw new \RuntimeException('Error with payment'); } $paymentId = $response->getPaymentId(); // use this for the next call redirect($response->getRedirectUrl());
此调用将返回AuthorizeResponse
对象。如果调用成功,则可以将客户重定向到redirectUrl
。根据下一屏幕的结果,客户将被重定向到成功或失败URL。
捕获
在您可以捕获付款之前,请确保使用fetchTransaction
调用已成功授权付款。
<?php $gateway = Omnipay::create('Paysafecard'); $gateway->setApiKey('yourApiKey'); $response = $gateway->fetchTransaction([ 'payment_id' = $paymentId ])->send(); if ($response->getStatus() === 'AUTHORIZED') { $captureResponse = $gateway->capture([ 'payment_id' = $paymentId ])->send(); }
退款
[可选] 您可以先调用validateRefund。根据Paysafecard的说法:"为了确保请求的退款可以继续,业务伙伴必须预先检查即将到来的退款是否可能成功,某些条件可能导致退款被拒绝"
<?php $gateway = Omnipay::create('Paysafecard'); $gateway->setApiKey('yourApiKey'); $validationResponse = $gateway->validateRefund([ 'payment_id' => $paymentId, 'amount' => 10.00, 'currency' => 'EUR', 'customer_email' => 'test@email.com', 'customer_id' => 1001, ])->send(); if (!$validationResponse->getStatus() != 'VALIDATION_SUCCESSFUL') { throw new \RuntimeException('Error with refund validation'); } $refundResponse = $gateway->refund([ 'payment_id' => $paymentId, 'refund_id' => $validationResponse->getRefundId(), ])->send(); if ($refundResponse->isSuccessful()) { // refund was successful }
或直接退款
<?php $gateway = Omnipay::create('Paysafecard'); $gateway->setApiKey('yourApiKey'); $refundResponse = $gateway->refund([ 'payment_id' => $paymentId, 'amount' => 10.00, 'currency' => 'EUR', 'customer_email' => 'test@email.com', 'customer_id' => 1001, ])->send(); if ($refundResponse->isSuccessful()) { // refund was successful }
测试
使用composer run test
运行单元测试
支持
如果您在Omnipay中遇到一般问题,我们建议在Stack Overflow上发帖。请务必添加omnipay标签,以便轻松找到。
如果您认为您已经发现了一个错误,请使用GitHub问题跟踪器报告它,或者更好的方法是分支库并提交一个pull请求。
参考
Paysafecard REST API文档 Omnipay Mollie v3(类似的JSON API)(官方包,用作模板)Omnipay Paysafecard Rest(Omnipay v2)