voguepay / voguepay
VoguePay API 库
README
安装过程
composer require voguepay/voguepay
安装后,在您的代码中包含 VoguePay 类。以下是一个示例:
require_once './vendor/autoload.php'; // location of the autoload file
use VoguePay\VoguePay;
该类将提供以下功能
VoguePay::card($payLoad);
VoguePay::chargeToken($payLoad);
VoguePay::getResponse($transactionDetails);
使用 PHP 库启动支付
使用 VoguePay::card 函数
VoguePay::card($payLoad);
require_once './vendor/autoload.php'; // location to the autoload file of the composer
use VoguePay\VoguePay;
$payLoad = [];
$payLoad = [
"version" => "2", // version of the API to be called
"merchant" => [
"merchantUsername" => "***", // Username of Merchant On VoguePay
"merchantID" => "***-***", // Merchant ID of account on VoguePay
"merchantEmail" => "***@gmail.com", // Registered email of account on VoguePay
"apiToken" => "TUDMQ735hNKNaQCBkZYVHvjHqNBk", // Command API Key of account on VoguePay
"publicKey" => file_get_contents('key.crt') // Public Key of account on Voguepay. This is to be copied and save to a file. The location of the file is to be replaced.
],
"card" => [
"name" => "***", //Card holder name
"pan" => "******************", //Card pan number
"month" => "05", //Card expiry month e.g 06
"year" => "21", //Card expiry year e.g 21
"cvv" => "***" //Card CVV number
],
"customer" => [
"email" => "***@gmail.com", // Email of customer
"phone" => "***********", // phone number of customer
"address" => "*************", // address of customer
"state" => "********", // state or province of customer
"zipCode" => "100005", // zip code of customer
"country" => "Nigeria" // country of country - Valid country or valid 3 letter ISO
],
"transaction" => [
"amount" => 100, //amount to be charged
"description" => "Payment Description Goes Here", //Description of payment
"reference" => "1x2345vbn", // Unique transaction reference, this is returned with the transaction details
"currency" => "USD", //Supported currency USD, GBP, EUR, NGN
],
"notification" => [
"callbackUrl" => "https://yourdomain.com/", // Url where a transaction details will be sent on transaction completion
"redirectUrl" => "https://yourdomain.com/inspection" // Url where the customer is redirected on transaction completion
],
"descriptor" => [
"companyName" => "****", // {Optional} - Company name
"countryIso" => "NGA" //3 letter country ISO
],
"demo" => false, // boolean (true / false) , set to true to initiate a demo transaction and false for live transaction
];
print_r(VoguePay::card($data));
以下是一个成功的响应示例
stdClass Object
(
[description] => Redirection Required - 3D Authentication required. // Response code description
[redirectUrl] => https://voguepay.com/?p=vpgate&ref=czoxMzoiNWNiZjQ2OTBlNDFkMCI7 // 3D redirection URL
[reference] => 1x2345vbn // Transaction reference
[response] => WL3D // Transaction response code
[status] => OK // API query status
[transactionID] => 5cbf4690e41d0 // Generated VoguePay transaction ID
)
在成功的 API 调用中,它返回一个包含 3D 认证 URL 的数据数组。[redirectUrl]
重定向到 3D 认证 URL 以完成交易。
如果发生错误,或者提供的详细信息无效,状态表示为 [status] => ERROR
以下是一个错误响应的示例
stdClass Object
(
[description] => Incorrect CVV
[field] => CVV
[reference] => 1x2345vbn
[response] => WL003
[status] => ERROR
)
状态 [status] => OK 并不表示交易成功。要获取交易状态,请检查 voguepay::getResponse() 的使用方法
交易完成后。发送一个 POST 请求 ($_POST['transaction_id']) 到包含在有效载荷中的回调 URL 和重定向 URL。这用于获取交易响应并验证交易是否成功
获取交易响应
oguepay::getResponse($transactionDetails)
以下是一个示例代码
require_once './vendor/autoload.php';
use VoguePay\VoguePay;
$data = [
"transactionID" => "5cbf4690e41d0",
"merchant" => [
"merchantUsername" => "***", // merchant username on VoguePay
"merchantID" => "***-***", // merchantID of account on VoguePay
"merchantEmail" => "***@gmail.com", // registered email address of account on VoguePay
"apiToken" => "TUDMQ735hNKNaQCBkZYVHvjHqNBk", // Command API token of account on VoguePay
],
];
print_r(VoguePay::getResponse($data));
以下是一个交易响应示例
stdClass Object
(
[apiProcessTime] => 0.002103 // API response time
[buyerDetails] => stdClass Object
(
[email] => ***@gmail.com // Customer Email address
[phone] => *********** // Customer Phone Number
[maskedPan] => 537010******6414 // Masked Pan used for payment
[cardType] => Mastercard // Card type
)
[description] => API query sucessful // API response description
[response] => OK // API response code
[status] => OK // API status
[transaction] => stdClass Object
(
[total] => 10.00 // Transaction Amount
[status] => Approved // Transaction status
[currencySymbol] => ₦ // Transaction currency symbol
[currency] => NGN // Transaction currency Code
[merchantID] => ***-*** // Merchant ID of merchant on VoguePay
[transactionID] => 5cbf4690e41d0 // Transaction ID of transaction on VoguePay
[transactionDate] => 2019-05-01 // Date of transaction
[transactionTime] => 08:30:53 // Time of transaction
[reference] => 1x2345vbn // Reference, returned as passed in the payload. This can be used to authenticate transaction on merchant side
[description] => This is a test payment //Payment description
[totalPaidByCustomer] => 10.00 // Total paid by the customer
[creditedToMerchant] => 9.85 // Amount credited to merchant account on VoguePay
[chargesPaid] => 0.15 // Total charges paid on transaction
[extraConfiguredCharges] => 0.00 // Extra configured charges if applicable
[fundsMaturity] => 2019-05-02 // Date of transaction maturity
[responseCode] => 00 // Transaction response code
[responseDescription] => Transaction Approved // Transaction response decription
)
)
解释交易响应
如前所述,API [status] 和 [response] 当为 OK 时,并不意味着交易已批准。
通过检查数组中的交易详细信息来解释已批准的交易。[transaction][status] 和 [transaction][responseCode]
A transaction is only to be approved when the transaction status [transaction][status] is equals to Approved and the transaction response code [transaction][responseCode] is equals to 00
以下是一个拒绝交易的示例代码
stdClass Object
(
[apiProcessTime] => 0.002103 // API response time
[buyerDetails] => stdClass Object
(
[email] => ***@gmail.com // Customer Email address
[phone] => *********** // Customer Phone Number
[maskedPan] => 537010******6414 // Masked Pan used for payment
[cardType] => Mastercard // Card type
)
[description] => API query sucessful // API response description
[response] => OK // API response code
[status] => OK // API status
[transaction] => stdClass Object
(
[total] => 10.00 // Transaction Amount
[status] => Declined // Transaction status
[currencySymbol] => ₦ // Transaction currency symbol
[currency] => NGN // Transaction currency Code
[merchantID] => ***-*** // Merchant ID of merchant on VoguePay
[transactionID] => 5cca90d020532 // Transaction ID of transaction on VoguePay
[transactionDate] => 2019-05-01 // Date of transaction
[transactionTime] => 08:30:53 // Time of transaction
[reference] => 1x2345vbn // Reference, returned as passed in the payload. This can be used to authenticate transaction on merchant side
[description] => This is a test payment //Payment description
[totalPaidByCustomer] => 0 // Total paid by the customer
[creditedToMerchant] => 0 // Amount credited to merchant account on VoguePay
[chargesPaid] => 0 // Total charges paid on transaction
[extraConfiguredCharges] => 0 // Extra configured charges if applicable
[fundsMaturity] => 2019-05-02 // Date of transaction maturity
[responseCode] => EC0571 // Transaction response code
[responseDescription] => Transaction not Permitted to Cardholder // Transaction response decription
)
)
卡片的标记化详细信息 [transaction][token] 可以保存并用于将来通过 VoguePay::chargeToken() 的借记
使用标记对卡片进行收费
使用 VoguePay::chargeToken()
以下是一个示例代码
require_once './vendor/autoload.php';
use VoguePay\VoguePay;
$data = [];
$data = [
"version" => "2", // version of the API to be called
"merchant" => [
"merchantUsername" => "***", // Username of Merchant On VoguePay
"merchantID" => "***-***", // Merchant ID of account on VoguePay
"merchantEmail" => "***@gmail.com", // Registered email of account on VoguePay
"apiToken" => "TUDMQ735hNKNaQCBkZYVHvjHqNBk", // Command API Key of account on VoguePay
"publicKey" => file_get_contents('key.crt') // Public Key of account on Voguepay. This is to be copied and save to a file. The location of the file is to be replaced.
],
"card" => [
"token" => "**********", // Transaction token
"cvv" => "948" //Card CVV number
],
"customer" => [
"email" => "***@gmail.com", // Email of customer
],
"transaction" => [
"amount" => 100, //amount to be charged
"description" => "This is a test payment", //Description of payment
"reference" => "1x2345vbn", // Unique transaction reference, this is returned with the transaction details
"currency" => "USD", //Supported currency USD, GBP, EUR, NGN
],
"descriptor" => [
"companyName" => "***", // {Optional} - Company name
"countryIso" => "NGA" // 3 letter country iso
],
];
print_r(VoguePay::chargeToken($data));
有关 VoguePay::chargeToken() 的示例响应,请参阅 VoguePay::getResponse() 的示例响应和说明。