globallypaid/php-sdk
Composer 安装命令:
composer require globallypaid/php-sdk
包简介
GloballyPaid Sdk implementation in PHP
README 文档
README
The official GloballyPaid PHP client library.
Requirements
PHP 5.6.0 and later.
Composer
You can install the bindings via Composer. Run the following command:
composer require globallypaid/php-sdk
require_once('vendor/autoload.php');
Manual Installation
If you do not wish to use Composer, you can download the latest release. Then, to use the bindings, include the config config.php (you can add in your framework or application config file) and main class GloballyPaidSDK.php file.
require_once('/path/to/globallypaid-sdk-php/src/GloballyPaidSDK.php');
Dependencies
The bindings require the following extensions in order to work properly:
If you use Composer, these dependencies should be handled automatically. If you install manually, you'll want to make sure that these extensions are available.
Getting Started
Simple configuration looks like:
//required config $config['PublishableApiKey'] = 'PublishableApiKey_here'; $config['AppId'] = 'AppId_here'; $config['SharedSecret'] = 'SharedSecret_here'; $config['Sandbox'] = true; //optional config //$config['ApiVersion'] = 'v1'; //default v1 //$config['RequestTimeout'] = 10; //default 30
Example: initialize the Client
require_once '../../config/config.php'; require_once '../../src/GloballyPaidSDK.php'; $GloballyPaid = new GloballyPaid($config); //config can be changed dynamically $GloballyPaid->setConfig([ 'PublishableApiKey' => 'PublishableApiKey_here', 'AppId' => 'AppId_here', 'SharedSecret' => 'SharedSecret_here', 'Sandbox' => true, 'ApiVersion' => 'v1', 'RequestTimeout' => 5 ]);
Documentation
Please see the PHP API docs for the most up-to-date documentation.
You can also refer to the GloballyPaid developers page.
Example
For a working example of usage, please visit Globally Paid PHP SDK example.
Initialize the Client
$GloballyPaid = new GloballyPaid($config);
Charges
Make a Instant Charge Sale Transaction
$charge = $GloballyPaid->charges->create([ 'source' => [ // the payment source object 'type' => 'card_on_file', // either card_on_file or credit_card 'card_on_file' => [ 'id' => 'token_id_here', // required 'cvv' => '123', // optionally pass the CVV for user attended transactions ] ], 'transaction' => [ // the transaction object 'amount' => 9.79 * 100, // integer amount in the smallest currency unit, 979 = 9.79 'currency_code' => 'USD', // ISO 4217 currency code 'country_code' => 'USA', // ISO 3166 Alpha-3 country code 'capture' => false, // false = authorization only, true = sale 'avs' => true, // perform address verification 'cof_type' => 'UNSCHEDULED_CARDHOLDER', // one of UNSCHEDULED_CARDHOLDER | UNSCHEDULED_MERCHANT | RECURRING | INSTALLMENT 'kount_session_id' => 'session id', 'save_payment_instrument' => false // if true, will save the payment instrument in our vault. We will return a payment instrument id that can be used for future payments. ] 'meta' => [ // the metadata object 'client_customer_id' => '123456', //your customer id 'client_transaction_id' => '987654', // your transaction id 'client_transaction_description' => 'Acme T-Shirt', // a short description for the transaction 'client_invoice_id' => 'INV-01293', // your invoice id 'shipping_info' => [ // shipping info for this transaction if available/applicable 'first_name' => 'John', 'last_name' => 'Doe', 'address' => [ 'line_1' => '123 Any St', 'line_2' => 'Apt B', 'city' => 'Irvine', 'state' => 'CA', 'postal_code' => '92714', 'country_code' => 'USA' ], 'phone' => '9495551212', 'email' => 'jdoe@nopmail.com' ] ] ]);
Make a Charge Sale Transaction With Capture
The transaction amount doesn’t reach the merchant account until the funds are captured.
//charge request $charge = $GloballyPaid->charges->create([ 'source' => [ 'type' => 'card_on_file', 'card_on_file' => [ 'id' => 'token_id_here', ] ], 'transaction' => [ 'amount' => 9.79 * 100, 'currency_code' => 'USD', 'country_code' => 'USA', 'capture' => false, 'avs' => true, 'cof_type' => 'UNSCHEDULED_CARDHOLDER', 'kount_session_id' => 'session id', ] 'meta' => [ 'client_customer_id' => '123456', 'client_transaction_id' => '987654', 'client_transaction_description' => 'Acme T-Shirt', 'client_invoice_id' => 'INV-01293', 'shipping_info' => [ 'first_name' => 'John', 'last_name' => 'Doe', 'address' => [ 'line_1' => '123 Any St', 'line_2' => 'Apt B', 'city' => 'Irvine', 'state' => 'CA', 'postal_code' => '92714', 'country_code' => 'USA' ], 'phone' => '9495551212', 'email' => 'jdoe@nopmail.com' ] ] ]); //capture request $capture = $GloballyPaid->charges->capture( $charge->id, $charge->amount );
Refund request
$refund = $GloballyPaid->charges->refund( 'charge_id_here', 20 * 100 // amount );
Customers
Create customer
$newCustomer = $GloballyPaid->customers->create([ 'client_customer_id' => 'client_customer_id_here', 'first_name' => 'John', 'last_name' => 'Smith', 'address' => [ 'line_1' => '123 Main St', 'line_2' => null, 'city' => 'NYC', 'state' => 'NY', 'postal_code' => '92657', 'country' => 'United States' ], 'phone' => '+123456789', 'email' => 'testemail@example.com' ]);
Get all customers
$customers = $GloballyPaid->customers->all(); foreach($customers as $customer){ //handle each $customer here }
Get customer by id
$existingCustomer = $GloballyPaid->customers->get('customer_id_here');
Update existing customer
$updateExistingCustomer = $GloballyPaid->customers->update('customer_id_here', [ 'first_name' => 'New name', 'last_name' => 'Smith', 'address' => [ 'line_1' => 'New address', ], 'email' => 'newemail@example123.com' ] );
Delete existing customer
$response = $GloballyPaid->customers->delete('customer_id_here');
Similar to customer crud is PaymentInstrument. You can check stand-alone examples to learn how to use.
Handling errors
You can handle errors for each request on same way $GloballyPaid->errors(). Check the example below:
require_once '../../config/config.php'; require_once '../../src/GloballyPaidSDK.php'; //init class object $GloballyPaid = new GloballyPaid($config); //get existing customer by id $existingCustomer = $GloballyPaid->customers->get('customer_id_here'); //if customer doesn't exist or any error happened -> handle errors if (!$existingCustomer) { $errors = $GloballyPaid->errors(); echo '<pre>'; var_dump($errors); echo '</pre>'; }
Debug and trace API calls (requests and responses)
Print debug data in formated pre tag
$GloballyPaid->debug(true);
Return debug data as array
You can use this way if you want to embed debug with your framework or application
$debugArrayData = $GloballyPaid->debug();
About
globallypaid-php-sdk is maintained and funded by Globally Paid. If you need help installing or using the library, please check the GloballyPaid Support Help Center.
If you've instead found a bug in the library or would like new features added, go ahead and open issues or pull requests against this repo GloballyPaid PHP SDK!
globallypaid/php-sdk 适用场景与选型建议
globallypaid/php-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 35 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 11 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「payment」 「pay」 「phpsdk」 「paymentgateway」 「globallypaid.com」 「globallypaid」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 globallypaid/php-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 globallypaid/php-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 globallypaid/php-sdk 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
LoginRadius PHP SDK v11.7.0
LoginRadius PHP SDK v11.7.0
Payyo Gateway for the Omnipay payment processing library
baidubce php sdk common package
Библиотека для приема платежей через Альфабанк.
Some pre-defined rules for validation in Omnipay payment processing library.
统计信息
- 总下载量: 35
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-11-15