Charge
With one-time token and fingerprint which are collected by Brick.js, you can then easily charge credit cards by using Charge API on your server side.
Charge request
In charge request, you can use this code sample to define the price and currency of your product. See charge API for the format of each parameter.
<?php
Paymentwall_Config::getInstance()->set(array(
'private_key' => 'YOUR_PRIVATE_KEY'
));
$parameters = $_POST;
$chargeInfo = array(
'email' => $parameters['email'],
'history[registration_date]' => '1489655092',
'amount' => 9.99,
'currency' => 'USD',
'token' => $parameters['brick_token'],
'fingerprint' => $parameters['brick_fingerprint'],
'description' => 'Order #123'
);
$charge = new Paymentwall_Charge();
$charge->create($chargeInfo);
?>
// We are using Express framework in this sample
var Paymentwall = require('paymentwall');
Paymentwall.Configure(
Paymentwall.Base.API_GOODS,
'YOUR_PUBLIC_KEY',
'YOUR_PRIVATE_KEY'
);
//custom parameters
var custom = {
'YOUR_CUSTOM_PARAMETER_NAME': 'YOUR_CUSTOM_PARAMETER_VALUE'
};
var parameters = req.body;
var charge = new Paymentwall.Charge(
0.5, //price
'USD', //currency code
'description', //description of the product
req.body.email, // user's email
req.body.brick_fingerprint, // fingerprint generated by Brick.js
req.body.brick_token, //one-time token
custom
);
charge.createCharge(function(brick_response){ }
Config.getInstance().setPublicKey("YOUR_PUBLIC_KEY");
Config.getInstance().setPrivateKey("YOUR_PRIVATE_KEY");
LinkedHashMap<String,String> chargemap = new LinkedHashMap<String, String>();
chargemap.put("token", request.getParameter("brick_token");
chargemap.put("email", "test@paymentwall.com");
chargemap.put("currency", "USD");
chargemap.put("amount", "9.99");
chargemap.put("fingerprint", request.getParameter("brick_fingerprint"));
chargemap.put("description", "description");
chargemap.put("additional_parameter_name", "additonal_parameter_value");
Charge charge = new Charge();
charge = (Charge)charge.create(chargemap);
curl https://payments.terminal3.com/api/brick/charge \
-H "X-ApiKey: [YOUR_PRIVATE_KEY]" \
-d "token=[TOKEN]" \
-d "amount=9.99" \
-d "currency=USD" \
-d "email=user@host.com" \
-d "fingerprint=[FINGERPRINT_BY_BRICK.JS]" \
-d "description=TestItem"
By default, Brick capture the charge at once, see authorize and capture if you prefer to do it later.
Charge response object
Once a charge request is successfully performed, you will get a charge response object which contains the payment information to help you verify your end users. See attributes for more details.
Each charge has its own id
which could be used for authorizing and capturing actions later.
Handle charge response
You can get the charge response object and redirect your customer to payment result pages by using below script.
Our risk team will help you to review the payment which is suspicious, which is possible to take 1 ~ 2 minutes. It is recommended to add a page to notify your customer that his/her payment is under review.
<?php
$response = $charge->getPublicData();
if ($charge->isSuccessful()) {
if ($charge->isCaptured()) {
// redirect your customer to payment success page
} elseif ($charge->isUnderReview()) {
// redirect your customer to payment under review page
}
} else {
// redirect your customer to payment failure page
$errors = json_decode($response, true);
echo $errors['error']['code'];
echo $errors['error']['message'];
}
?>
charge.createCharge(function(brick_response){
if(brick_response.isSuccessful()){
if(brick_response.isCaptured()){
charge_id = brick_response.getChargeId();
// redirect your customer to payment success page
} else if(brick_response.isUnderReview()){
charge_id = brick_response.getChargeId();
// redirect your customer to payment under review page
} else if(brick_response.isUnder3DSecure()){
// Handle 3d secure
return_page = brick_response.get3DHtml();
};
} else{
// Redirect your customer to payment failure page
error_code = brick_response.getErrorCode();
error_details = brick_response.getErrorDetails();
};
brick_response.getFullResponse();
brick_response.getFullResponse('JSON');
});
JSONObject response = charge.getPublicData();
if (charge.isSuccessful()){
if (charge.isCaptured()){
// redirect your customer to payment success page
} else if (charge.isUnderReview()){
// redirect your customer to payment under review page
} else {
// redirect your customer to payment failure page
}
}
Terminal3 Payments instant payment notification, pingback, will be sent immediately once a charge request is achieved. Your delivery should be performed according to the type of our pingback. You may also define your own parameter as additional parameters in charge request which can be set as custom pingback parameters for transparent transmission in charge request.
Storing a card after charge
If you want to store the credit card for future use, you can store the permanent token, card.token
field of charge response object, and use it for a new charge request later.
<?php
$parameters = $_POST;
$charge = new Paymentwall_Charge();
$charge->create(array(
'token' => 'PERMANENT_TOKEN', // replace it with the stored permanent token
'email' => $parameters['email'],
'history[registration_date]' => '1489755092',
'currency' => 'USD',
'amount' => 9.99,
'description' => 'Order #123'
));
?>
var charge = new Paymentwall.Charge(
0.5,
'USD',
'description',
'test@paymentwall.com',
'PERMNANET_TOKEN', // replace it with the stored permanent token
{'custom[param_name]':'param_value'}
);
charge.createCharge(function(brick_response){
// Handle response
});
Charge charge = new Charge();
charge = (Charge)charge.create(new HashMap<String, String>(){{
put("token", "PERMANENT_TOKEN"); // replace it with the stored permanent token
put("email", "test@paymentwall.com");
put("currency", "USD");
put("amount", "9.99");
put("description", "description");
put("additional_parameter_name", "additonal_parameter_value");
}});
curl https://payments.terminal3.com/api/brick/charge \
-H "X-ApiKey: [YOUR_PRIVATE_KEY]" \
-d "token=[PERMANENT_TOKEN]" \
-d "amount=9.99" \
-d "currency=USD" \
-d "email=user@host.com" \
-d "description=TestItem"
Authorize and capture
Parameter options[capture]
can be used in charge request for people who want to capture charge later.
Brick charge request will only do pre-authorization if options[capture]=0
( By default options[capture]=1
) and put a temporary “hold” on the funds for 7 days. The capture action will be declined if the pre-authorization has expired.
You can use the id
of charge response object to capture the funds during the period.
<?php
require_once('path/to/lib/paymentwall.php');
Paymentwall_Config::getInstance()->set(array(
'private_key' => 'YOUR_PRIVATE_KEY'
));
$charge = new Paymentwall_Charge($chargeid);
$charge->capture();
$response=$charge->getPublicData();
echo $response;
?>
var charge = new Paymentwall.Charge();
charge.otherOperation(chargeid,'capture',function(brick_response){
brick_response.getFullResponse('JSON');
});
Charge charge = new Charge(chargeId);
charge.capture();
JSONObject response = charge.getPublicData();
curl https://payments.terminal3.com/api/brick/charge/$chargeid/capture \
-H "X-ApiKey: [YOUR_PRIVATE_KEY]" \
At the same time, you can also void the funds if you don’t want to capture it.
<?php
require_once('path/to/lib/paymentwall.php');
Paymentwall_Config::getInstance()->set(array(
'private_key' => 'YOUR_PRIVATE_KEY'
));
$charge = new Paymentwall_Charge($chargeid);
$charge->void();
$response=$charge->getPublicData();
echo $response;
?>
var charge = new Paymentwall.Charge();
charge.otherOperation(chargeid,'void',function(brick_response){
brick_response.getFullResponse('JSON');
});
Charge charge = new Charge(chargeId);
charge.void_();
JSONObject response = charge.getPublicData();
curl https://payments.terminal3.com/api/brick/charge/$chargeid/void \
-H "X-ApiKey: [YOUR_PRIVATE_KEY]" \
Next Step
You are almost done! Your payment system now can handle the payments which don’t have 3D secure enabled. In order to make your payment system support 3D secure payments,
- See how to apply 3d secure.