swiftmade / omnipay-everypay
(非官方) 埃斯托尼亚Every Pay(Every Pay)的支付网关
v0.4.4
2023-11-29 09:21 UTC
Requires
- php: ^7.2|^8
- ext-json: *
- league/omnipay: ^3
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.2
- omnipay/tests: ^4.1
- phpunit/phpunit: ^8.5|^9
This package is not auto-updated.
Last update: 2024-09-18 12:49:31 UTC
README
PHP EveryPay 客户端(用于 Omnipay)
使用此包通过 Omnipay 将 EveryPay 集成到您的 PHP 应用程序中。
EveryPay 是一个支付网关,目前由以下公司使用
- LHV
- SEB
- Swedbank
该包支持以下支付类型
- 一次性付款
- 请求卡令牌
- 一键/客户发起交易(CIT)付款
- 商家发起交易(MIT)付款
使用方法
使用 composer 安装包
composer require swiftmade/omnipay-everypay
初始化网关
$gateway = Omnipay::create('EveryPay')->initialize([ 'username' => '', // EveryPay api username 'secret' => '', // EveryPay api secret 'accountName' => '', // merchant account ID 'testMode' => true, // set to false for production! 'locale' => 'en', // et=Estonian, see integration guide for more options. ]);
一次性购买
$purchase = $gateway ->purchase([ 'amount' => $amount, 'paymentType' => PaymentType::ONE_OFF, ]) ->setTransactionId($orderId) // unique order id for this purchase ->setReturnUrl($customerUrl) // the url to redirect if the payment fails or gets cancelled ->setClientIp($_SERVER['REMOTE_ADDR']) // optional, helps fraud detection ->setEmail(''); // optional, helps fraud detection // Use this, if you want to make the payment using a previously stored card token // Only applicable for MIT and CIT payment types. $purchase->setCardReference($token); // Uncomment if you want to store the card as a token after the payment // (Only supported with One-off payment type) $purchase->setSaveCard(true); $response = $purchase->send(); // IMPORTANT: Store this payment data somewhere so that we can validate / process it later $payment = $response->getData(); return $response->redirect(); // this will return a self-submitting html form to EveryPay Gateway API
客户发起交易(一键支付)
$purchase = $gateway ->purchase([ 'amount' => $amount, 'paymentType' => PaymentType::CIT, ]) ->setTransactionId($orderId) // unique order id for this purchase ->setCardReference('previously stored card token') ->setReturnUrl($customerUrl) ->setClientIp($_SERVER['REMOTE_ADDR']) // optional, helps fraud detection ->setEmail(''); // optional, helps fraud detection $response = $purchase->send(); // Store the payment response data if you wish. $payment = $response->getData(); if ($response->isSuccessful()) { // Payment done! } else if($response->isRedirect()) { // 3DS Confirmation needed! // Redirect the user to 3DS Page. return $response->redirect(); } else { // Something went wrong! // Check $response->getMessage(); }
完成支付(处理 EveryPay 的网关重定向)
一旦支付完成,EveryPay 将将用户重定向到 returnUrl
。您需要验证支付是否成功。
// Here, pass the payment array that we previously stored when creating the payment $response = $gateway->completePurchase() // These values are passed back to you by EveryPay ->setTransactionId($_GET['order_reference']) ->setTransactionReference($_GET['payment_reference']) ->send(); if (!$response->isSuccessful()) { // Payment failed! // Check $response->getMessage() for more details. } // Payment succeeded! // Here's your payment reference number: $response->getTransactionReference() if ($card = $response->getCardToken()) { // You also got back a card token // Store this somewhere safe for future use! }
授权和稍后捕获
在 EveryPay 中,支付的捕获时间是在账户级别配置的。如果您想授权一个不需要捕获的支付,则需要相应配置商家账户。
要授权支付,只需将 purchase
和 completePurchase
方法替换为 authorize
和 completeAuthorize
。然后调用 capture
来捕获资金。
// Here, pass the payment array that we previously stored when creating the payment $gateway->authorize([ 'amount' => $amount, 'paymentType' => PaymentType::CIT, ]) ->setCardReference('previously stored card token') // Set all the other parameters. See previous examples ... ->send(); // Redirect the user to 3DS confirmation as necessary. // When EveryPay redirects the user back, do this... // This won't capture the payment yet, but makes sure the authorization is successful. $authorizeResponse = $gateway->completeAuthorize() ->setTransactionId($_GET['order_reference']) ->setTransactionReference($_GET['payment_reference']) ->send(); // Hold on to this.. You'll use this reference to capture the payment. $paymentReference = $authorizeResponse->getTransactionReference(); // When you're ready to capture, call: $response = $gateway->capture([ 'amount' => $amount, // You can capture partially, or the whole amount. 'transactionReference' => $paymentReference, ])->send(); if ($response->isSuccessful()) { // Payment captured! } else { // Something went wrong! // Check $response->getMessage(); }
安全
如果您发现任何安全相关的问题,请通过电子邮件 hello@swiftmade.co 而不是使用问题跟踪器。
免责声明
此包不是 EveryPay AS 或 Omnipay 的官方包。
许可
MIT 许可证(MIT)。有关更多信息,请参阅许可文件。