vicomm / sdk
该软件包的最新版本(1.3.0)没有可用的许可证信息。
Vicomm PHP 客户端
1.3.0
2022-06-10 18:22 UTC
Requires
- guzzlehttp/guzzle: ^7.4.2
Requires (Dev)
- phpunit/phpunit: ^7
This package is auto-updated.
Last update: 2024-09-10 23:26:48 UTC
README
# Vicomm PHP SDK
安装
通过 composer 安装(尚未托管在 Packagist 上)
composer require vicomm/sdk
## 使用方法
<?php require 'vendor/autoload.php'; use Vicomm\Vicomm; // First setup your credentials provided by vicomm $applicationCode = "SOME_APP_CODE"; $applicationKey = "SOME_APP_KEY"; Vicomm::init($applicationCode, $applicationKey);
设置凭证后,您可以使用可用的资源。
可用资源
- 卡片
- 可用方法:
getList
,delete
- 收费
- 可用方法:
create
,authorize
,capture
,verify
,refund
- 现金
- 可用方法:
generateOrder
### 卡片
有关这些功能的完整文档请参阅 此处。
列表
<?php use Vicomm\Vicomm; use Vicomm\Exceptions\VicommErrorException; Vicomm::init($applicationCode, $aplicationKey); $card = Vicomm::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 (VicommErrorException $error) { // Details of exception echo $error->getMessage(); // You can see the logs for complete information }
收费
有关这些功能的完整文档请参阅 此处。
创建新收费
有关此功能的完整文档请参阅 此处
<?php use Vicomm\Vicomm; use Vicomm\Exceptions\VicommErrorException; // Card token $cardToken = "myAwesomeTokenCard"; $charge = Vicomm::charge(); $userDetails = [ 'id' => "1", // Field required 'email' => "cbenavides@gpvicomm.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 (VicommErrorException $error) { // See the console output for complete information // Access to HTTP code from vicomm 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 Vicomm\Vicomm; use Vicomm\Exceptions\VicommErrorException; // Card token $cardToken = "myAwesomeTokenCard"; $charge = Vicomm::charge(); $userDetails = [ 'id' => "1", // Field required 'email' => "cbenavides@gpvicomm.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 (VicommErrorException $error) { // See the console output for complete information // Access to HTTP code from vicomm 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 Vicomm\Vicomm; use Vicomm\Exceptions\VicommErrorException; $charge = Vicomm::charge(); $authorization = $charge->authorize($cardToken, $orderDetails, $userDetails); $transactionId = $authorization->transaction->id; try { $capture = $charge->capture($transactionId); } catch (VicommErrorException $error) { // See the console output for complete information // Access to HTTP code from vicomm 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 Vicomm\Vicomm; use Vicomm\Exceptions\vicommErrorException; $charge = Vicomm::charge(); $created = $charge->create($cardToken, $orderDetails, $userDetails); $transactionId = $created->transaction->id; try { $refund = $charge->refund($transactionId); } catch (VicommErrorException $error) { // See the console output for complete information // Access to HTTP code from vicomm 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 Vicomm\Vicomm; use Vicomm\Exceptions\VicommErrorException; $cash = Vicomm::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 (VicommErrorException $error) { // See the console output for complete information // Access to HTTP code from vicomm 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