ilrwebservices/cardpointe-gateway-rest-api-client
Composer 安装命令:
composer require ilrwebservices/cardpointe-gateway-rest-api-client
包简介
PHP library for the CardPointe Gateway API
关键字:
README 文档
README
A simple PHP http client for the CardPointe Gateway REST API. Optimized for JSON and authentication via username and password. Based on Guzzle.
CardPointeGatewayRestClient is an extended GuzzleHttp\Client, so it can do all the things that Guzzle can and a bit more.
Be sure to refer to the CardPointe Gateway API documentation for details.
Installation
Via composer:
composer require ilrwebservices/cardpointe-gateway-rest-api-client
Usage
<?php require __DIR__ . '/../vendor/autoload.php'; use CardPointeGateway\CardPointeGatewayRestClient; $client = new CardPointeGatewayRestClient([ 'cp_user' => $_ENV['CARDPOINTE_GATEWAY_API_USER'], 'cp_pass' => $_ENV['CARDPOINTE_GATEWAY_API_PASS'], 'cp_site' => 'fts', ]);
Note how these settings are passed into the client constructor options along with other Guzzle-compatible options. In this example, some sensitive settings are stored in environment variables since they should not be stored in code.
The CardPointeGatewayRestClient will set the base_uri option to https://<cp_site>.cardconnect.com/cardconnect/rest/ automatically.
You can now make API calls just as you would in Guzzle:
$client_response = $client->request('GET', 'https://<cp_site>.cardconnect.com/cardconnect/rest/inquireMerchant/<merchid>');
Since the base_uri option is pre-configured, you can use a relative URL (be sure not to add a leading /, though):
$client_response = $client->request('GET', 'inquireMerchant/<merchid>');
And because it's Guzzle, there are shorthand methods:
$client_response = $client->get('inquireMerchant/<merchid>');
Responses are PSR-7 response messages, just like Guzzle, so you can get returned data via getBody():
$client_data_raw = (string) $client_response->getBody(); // Returns: // { // "site": "fts", // "acctupdater": "N", // "cvv": "N", // "cardproc": "RPCT", // "fee_type": "N", // "enabled": true, // "echeck": "N", // "merchid": "xxxxxxxxxxxx", // "avs": "N" // }
For application/json responses, CardPointeGatewayRestClient adds a non-standard getData() method that decodes the JSON response for you:
$client_data = $client_response->getData(); // Returns: // Array // ( // [site] => fts // [acctupdater] => N // [cvv] => N // [cardproc] => RPCT // [fee_type] => N // [enabled] => 1 // [echeck] => N // [merchid] => xxxxxxxxxxxx // [avs] => N // )
Be careful with large responses, however, as they can consume too much memory.
Sending JSON data to API endpoints can be done using the json request option from Guzzle:
$new_client_response = $client->post('auth', [ 'json' => [ 'merchid' => 'xxxxxxxxxxxx', 'amount' => '20.01', 'expiry' => 'MMYY', 'account' => '4111111111111111', 'cvv2' => '123', ], ]);
Error handling
You can use Guzzle exceptions for error handling. CardPointe Gateway API endpoints generally use 4xx codes for errors, so GuzzleHttp\Exception\ClientException is a good match for catching those errors.
try { $new_client_response = $client->post('auth', [ 'json' => [ 'merchid': 'xxxxxxxxxxxx', 'amount': '20.01', 'expiry': 'MMYY', 'account': '4111111111111111', 'cvv2': '123', ], ]); } // Could not connect to server or other network issue. catch (\GuzzleHttp\Exception\ConnectException $e) { print_r($e->getMessage()); } // 4xx error. This is either a 400 Bad Request (e.g. invalid syntax) or // 401 Unauthorized (e.g. bad credentials). catch (\GuzzleHttp\Exception\ClientException $e) { print_r($e->getResponse()->getData()); print_r($e->getMessage()); } // 5xx error. This is an 'Internal Server Error'. catch (\GuzzleHttp\Exception\ServerException $e) { print_r($e->getResponse()->getData()); print_r($e->getMessage()); }
Inspired by drewm/mailchimp-api.
ilrwebservices/cardpointe-gateway-rest-api-client 适用场景与选型建议
ilrwebservices/cardpointe-gateway-rest-api-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 175 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 03 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「cardpointe」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ilrwebservices/cardpointe-gateway-rest-api-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ilrwebservices/cardpointe-gateway-rest-api-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ilrwebservices/cardpointe-gateway-rest-api-client 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP adapter for CardConnect CardPointe API
CardPointe gateway for Omnipay payment processing library
A PSR-7 compatible library for making CRUD API endpoints
PHP adapter for CardConnect CardPointe API
PHP adapter for CardConnect CardPointe API
PHP adapter for CardConnect CardPointe API
统计信息
- 总下载量: 175
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-03-11