PHP code example of globallypaid / php-sdk
1. Go to this page and download the library: Download globallypaid/php-sdk library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
globallypaid / php-sdk example snippets
//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
$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
]);
$GloballyPaid = new GloballyPaid($config);
$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', // it, 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' => '[email protected] '
]
]
]);
//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' => '[email protected] '
]
]
]);
//capture request
$capture = $GloballyPaid->charges->capture(
$charge->id,
$charge->amount
);
$refund = $GloballyPaid->charges->refund(
'charge_id_here',
20 * 100 // amount
);
$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' => '[email protected] '
]);
$customers = $GloballyPaid->customers->all();
foreach($customers as $customer){
//handle each $customer here
}
$existingCustomer = $GloballyPaid->customers->get('customer_id_here');
$updateExistingCustomer = $GloballyPaid->customers->update('customer_id_here',
[
'first_name' => 'New name',
'last_name' => 'Smith',
'address' => [
'line_1' => 'New address',
],
'email' => '[email protected] '
]
);
$response = $GloballyPaid->customers->delete('customer_id_here');
//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>';
}
$GloballyPaid->debug(true);
$debugArrayData = $GloballyPaid->debug();
bash
composer