PHP code example of smartcoin / smartcoin-php
1. Go to this page and download the library: Download smartcoin/smartcoin-php 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/ */
smartcoin / smartcoin-php example snippets
\Smartcoin\Smartcoin::api_key('pk_test_407d1f51a61756');
\Smartcoin\Smartcoin::api_secret('sk_test_86e4486a0078b2');
//Credit Card Charge without token as card param
try {
$charge = \Smartcoin\Charge::create(array(
'amount' => 100,
'currency' => 'brl',
'card' => array(
'number' => '4242424242424242',
'exp_month' => 10,
'exp_year' => 15,
'cvc' => '083'
),
'description' => 'Smartcoin charge test for [email protected] '
));
echo $charge->to_json();
}catch(\Smartcoin\Error $e){
echo json_encode($e->get_json_body());
}
//Credit Card Charge with token as card param
try {
$charge = \Smartcoin\Charge::create(array(
'amount' => 100,
'currency' => 'brl',
'card' => 'tok_434343434343434343434',
'description' => 'Smartcoin charge test for [email protected] '
));
echo $charge->to_json();
}catch(\Smartcoin\Error $e){
echo json_encode($e->get_json_body());
}
//Bank Slip Charge
try {
$charge = \Smartcoin\Charge::create(array(
'amount' => 1000,
'currency' => 'brl',
'type' => 'bank_slip'
));
echo $charge->to_json();
}catch(\Smartcoin\Error $e){
echo json_encode($e->get_json_body());
}
//Create Subscription
try {
$customer = \Smartcoin\Customer::create(array(
'email' => '[email protected] ',
"card" => array('number' => 5454545454545454,
'exp_month' => 11,
'exp_year' => 2017,
'cvc' => 111,
'name' => 'Doctor Who')
));
$sub = $customer->subscriptions()->create(array(
'plan' => 'silver'
));
echo $sub->to_json();
}catch(\Smartcoin\Error $e){
echo json_encode($e->get_json_body());
}
php ./test/Smartcoin.php