paymentez / sdk
此软件包的最新版本(1.3.0)没有可用的许可证信息。
Paymentez PHP 客户端
1.3.0
2022-06-09 22:08 UTC
Requires
- guzzlehttp/guzzle: ^7.4.2
Requires (Dev)
- phpunit/phpunit: ^7
This package is auto-updated.
Last update: 2024-09-10 03:17:25 UTC
README
# Paymentez PHP SDK
安装
通过 composer 安装(尚未托管在 packagist 上)
composer require paymentez/sdk
## 使用
<?php require 'vendor/autoload.php'; use Paymentez\Paymentez; // First setup your credentials provided by paymentez $applicationCode = "SOME_APP_CODE"; $applicationKey = "SOME_APP_KEY"; Paymentez::init($applicationCode, $applicationKey);
一旦设置好凭证,您就可以使用可用资源。
可用资源
- 卡
- 可用方法:
getList
,delete
- 扣款
- 可用方法:
create
,authorize
,capture
,verify
,refund
- 现金
- 可用方法:
generateOrder
### 卡
有关这些功能的完整文档请参见 此处。
列表
<?php use Paymentez\Paymentez; use Paymentez\Exceptions\PaymentezErrorException; Paymentez::init($applicationCode, $aplicationKey); $card = Paymentez::card(); // Success response $userId = "1"; $listOfUserCards = $card->getList($userId); $totalSizeOfCardList = $listOfUserCards->result_size; $listCards = $listOfUserCards->cards; // Get all data of response $response = $listOfUserCards->getData(); // Catch fail response try { $listOfUserCards = $card->getList("someUID"); } catch (PaymentezErrorException $error) { // Details of exception echo $error->getMessage(); // You can see the logs for complete information }
扣款
有关这些功能的完整文档请参见 此处。
创建新扣款
有关此功能的完整文档请参见 此处
<?php use Paymentez\Paymentez; use Paymentez\Exceptions\PaymentezErrorException; // Card token $cardToken = "myAwesomeTokenCard"; $charge = Paymentez::charge(); $userDetails = [ 'id' => "1", // Field required 'email' => "cbenavides@paymentez.com" // Field required ]; $orderDetails = [ 'amount' => 100.00, // Field required 'description' => "XXXXXX", // Field required 'dev_reference' => "XXXXXX", // Field required 'vat' => 0.00 // Field required ]; try { $created = $charge->create($cardToken, $orderDetails, $userDetails); } catch (PaymentezErrorException $error) { // See the console output for complete information // Access to HTTP code from paymentez service $code = $error->getCode(); $message = $error->getMessage(); } // Get transaction status $status = $created->transaction->status; // Get transaction ID $transactionId = $created->transaction->id; // Get authorization code $authCode = $created->transaction->authorization_code;
授权扣款
有关此功能的完整文档请参见 此处
<?php use Paymentez\Paymentez; use Paymentez\Exceptions\PaymentezErrorException; // Card token $cardToken = "myAwesomeTokenCard"; $charge = Paymentez::charge(); $userDetails = [ 'id' => "1", // Field required 'email' => "cbenavides@paymentez.com" // Field required ]; $orderDetails = [ 'amount' => 100.00, // Field required 'description' => "XXXXXX", // Field required 'dev_reference' => "XXXXXX", // Field required 'vat' => 0.00 // Field required ]; try { $authorization = $charge->authorize($cardToken, $orderDetails, $userDetails); } catch (PaymentezErrorException $error) { // See the console output for complete information // Access to HTTP code from paymentez service $code = $error->getCode(); $message = $error->getMessage(); } // Get transaction status $status = $authorization->transaction->status; // Get transaction ID $transactionId = $authorization->transaction->id; // Get authorization code $authCode = $authorization->transaction->authorization_code;
捕获
有关此功能的完整文档请参见 此处
需要执行 授权流程
<?php use Paymentez\Paymentez; use Paymentez\Exceptions\PaymentezErrorException; $charge = Paymentez::charge(); $authorization = $charge->authorize($cardToken, $orderDetails, $userDetails); $transactionId = $authorization->transaction->id; try { $capture = $charge->capture($transactionId); } catch (PaymentezErrorException $error) { // See the console output for complete information // Access to HTTP code from paymentez service $code = $error->getCode(); $message = $error->getMessage(); } // Get transaction status $status = $capture->transaction->status; // Make a capture with different amount $newAmountForCapture = 1000.46; $capture = $charge->capture($transactionId, $newAmountForCapture);
退款
有关此功能的完整文档请参见 此处
需要执行 创建流程
<?php use Paymentez\Paymentez; use Paymentez\Exceptions\PaymentezErrorException; $charge = Paymentez::charge(); $created = $charge->create($cardToken, $orderDetails, $userDetails); $transactionId = $created->transaction->id; try { $refund = $charge->refund($transactionId); } catch (PaymentezErrorException $error) { // See the console output for complete information // Access to HTTP code from paymentez service $code = $error->getCode(); $message = $error->getMessage(); } // Get status of refund $status = $refund->status; $detail = $refund->detail; // Make a partial refund $partialAmountToRefund = 10; $refund = $charge->refund($transactionId, $partialAmountToRefund);
### 现金
生成订单
有关所有可用选项请参见 此处
<?php use Paymentez\Paymentez; use Paymentez\Exceptions\PaymentezErrorException; $cash = Paymentez::cash(); $carrierDetails = [ 'id' => 'oxxo', // Field required 'extra_params' => [ // Depends of carrier, for oxxo is required 'user' => [ // For oxxo is required 'name' => "Juan", 'last_name' => "Perez" ] ] ]; $userDetails = [ 'id' => "1", // Field required 'email' => "randm@mail.com" // Field required ]; $orderDetails = [ 'dev_reference' => "XXXXXXX", // Field required 'amount' => 100, // Field required 'expiration_days' => 1, // Field required 'recurrent' => false, // Field required 'description' => "XXXXXX" // Field required ]; try { $order = $cash->generateOrder($carrierDetails, $userDetails, $orderDetails); } catch (PaymentezErrorException $error) { // See the console output for complete information // Access to HTTP code from paymentez service $code = $error->getCode(); $message = $error->getMessage(); } // Get reference code $referenceCode = $order->transaction->reference; // Get expiration date $expirationData = $order->transaction->expiration_date; // Get order status $status = $order->transaction->status;
运行单元测试
composer run test