flydev-fr / vivawallet-php
Viva Wallet 原生结账 V2 API PHP 封装库
1.0.0
2021-01-04 20:34 UTC
Requires
- php: >=7.3.0
- egulias/email-validator: ~2.0
- guzzlehttp/guzzle: ~7.1
This package is auto-updated.
Last update: 2024-09-05 04:55:57 UTC
README
这是 Viva Wallet 原生结账 V2 API 的封装库:https://developer.vivawallet.com/online-checkouts/native-checkout-v2/
如何使用
该库通过 Composer 安装。您需要要求 flydev-fr/viva-php
composer require flydev-fr/viva-php:~1.0
先决条件
从 https://developer.vivawallet.com/online-checkouts/native-checkout-v2/ 完成所有先决条件步骤,并获取您的 Client ID 和 Client Secret。您需要设置一个使用原生结账 V2 作为集成方法的支付源,并获取一个 Source Code。
获取卡费用令牌
如此处所述,在前端创建支付表单和 Charge Token:https://developer.vivawallet.com/online-checkouts/native-checkout-v2/ 您需要在前端获取 Access Token 和 Base URL,您可以通过以下方式获取它们
$baseUrl = \FlydevFr\Viva\Transaction\Url::getUrl("[Test Mode]"); // Test mode, default is false $accessToken = (new \FlydevFr\Viva\Account\Authorization()) ->setClientId("[Client ID]") // Client ID, Provided by wallet ->setClientSecret("[Client Secret]") // Client Secret, Provided by wallet ->setTestMode("[Test Mode]") // Test mode, default is false, can be skipped ->getAccessToken();
现在,当您有了 Charge Token,您可以进行实际交易。
交易
CHARGE
$customer = (new \FlydevFr\Viva\Transaction\Customer()) ->setEmail("[Customer Email]") ->setPhone("[Customer Phone]") ->setFullName("[Customer Full Name]"); $transaction = (new FlydevFr\Viva\Transaction\Charge()) ->setClientId("[Client ID]") // Client ID, Provided by wallet ->setClientSecret("[Client Secret]") // Client Secret, Provided by wallet ->setTestMode("[Test Mode]") // Test mode, default is false, can be skipped ->setSourceCode("[Source Code]") // Source code, provided by wallet ->setAmount((int) "[Amount]") // The amount to charge in currency's smallest denomination (e.g amount in pounds x 100) ->setInstallments((int) "[Installments]") // Installments, can be skipped if not used ->setChargeToken("[Charge Token]") // Charge token obtained at front end ->setCustomer($customer); $result = $transaction->send(); if (!empty($transaction->getError())) { // Log the error message // $error = $transaction->getError(); } else { // Save transaction id // $transactionId = $result->transactionId; }
AUTHORIZATION
$customer = (new \FlydevFr\Viva\Transaction\Customer()) ->setEmail("[Customer Email]") ->setPhone("[Customer Phone]") ->setFullName("[Customer Full Name]"); $transaction = (new FlydevFr\Viva\Transaction\Authorization()) ->setClientId("[Client ID]") // Client ID, Provided by wallet ->setClientSecret("[Client Secret]") // Client Secret, Provided by wallet ->setTestMode("[Test Mode]") // Test mode, default is false, can be skipped ->setSourceCode("[Source Code]") // Source code, provided by wallet ->setAmount((int) "[Amount]") // The amount to pre-auth in currency's smallest denomination (e.g amount in pounds x 100) ->setInstallments((int) "[Installments]") // Installments, can be skipped if not used ->setChargeToken("[Charge Token]") // Charge token obtained at front end ->setCustomer($customer); $result = $transaction->send(); if (!empty($transaction->getError())) { // Log the error message // $error = $transaction->getError(); } else { // Save transaction id // $transactionId = $result->transactionId; }
CAPTURE
确保您已启用账户中的定期付款。
$transaction = (new \FlydevFr\Viva\Transaction\Capture()) ->setClientId("[Client ID]") // Client ID, Provided by wallet ->setClientSecret("[Client Secret]") // Client Secret, Provided by wallet ->setTestMode("[Test Mode]") // Test mode, default is false, can be skipped ->setTransactionId("[Transaction ID]") // Transaction id of authorization transaction ->setAmount((int) "[Amount]"); // The amount to capture in currency's smallest denomination (e.g amount in pounds x 100) $result = $transaction->send(); if (!empty($transaction->getError())) { // Log the error message // $error = $transaction->getError(); } else { // Save transaction id // $transactionId = $result->transactionId; }
CANCEL
确保您已启用账户中的退款。
$transaction = (new \FlydevFr\Viva\Transaction\Cancel()) ->setClientId("[Client ID]") // Client ID, Provided by wallet ->setClientSecret("[Client Secret]") // Client Secret, Provided by wallet ->setTestMode("[Test Mode]") // Test mode, default is false, can be skipped ->setSourceCode("[Source Code]") // Source code, provided by wallet ->setTransactionId("[Transaction ID]") // Transaction id of charge, authorization or capture transaction ->setAmount((int) "[Amount]"); // The amount to refund in currency's smallest denomination (e.g amount in pounds x 100) $result = $transaction->send(); if (!empty($transaction->getError())) { // Log the error message // $error = $transaction->getError(); } else { // Save transaction id // $transactionId = $result->transactionId; }
在后台获取费用令牌
可以在后台获取费用令牌。在自定义集成中可能需要它,更多详细信息请参阅此处:https://developer.vivawallet.com/online-checkouts/native-checkout-v2/
$transaction = (new \FlydevFr\Viva\Transaction\ChargeToken()) ->setClientId("[Client ID]") // Client ID, Provided by wallet ->setClientSecret("[Client Secret]") // Client Secret, Provided by wallet ->setTestMode("[Test Mode]") // Test mode, default is false, can be skipped ->setAmount((int) "[Amount]"); // The amount in currency's smallest denomination (e.g amount in pounds x 100) ->setCvc("[Cvc code]") // Card cvc code ->setNumber("[Card number]") // Card number ->setHolderName("[Holder name]") // Card holder name ->setExpirationYear((int) "[Expiration Year]") // Card expiration year ->setExpirationMonth((int) "[Expiration Month]") // Card expiration month ->setSessionRedirectUrl("[Session redirect url]"); // Url to redirect when authentication session finished $result = $transaction->send(); if (!empty($transaction->getError())) { // Log the error message // $error = $transaction->getError(); } else { // Get charge token // $chargeToken = $result->chargeToken; // $redirectToACSForm = $result->redirectToACSForm; }
检查分期付款
检索卡上允许的最大分期付款次数。
$transaction = (new \FlydevFr\Viva\Transaction\Installments()) ->setClientId("[Client ID]") // Client ID, Provided by wallet ->setClientSecret("[Client Secret]") // Client Secret, Provided by wallet ->setTestMode("[Test Mode]") // Test mode, default is false, can be skipped ->setNumber("[Card number]"); // Card number $result = $transaction->send(); if (!empty($transaction->getError())) { // Log the error message // $error = $transaction->getError(); } else { // Get number of installments // $installments = $result->maxInstallments; }