# API: Add Credit Card
# addClientCreditCard
Add credit card to client profile
# Required parameters
Parameter | Description |
---|---|
id | Client ID |
cardnum | Credit Card number |
cardtype | Credit Card type |
expiryyear | Credit Card Expiration year, example: 25 |
expirymonth | Credit Card Expiration month, example: 12 |
# Optional parameters
Parameter | Description |
---|---|
token | Card Token if it was tokenized already by gateway module, use with token_gateway_id |
token_gateway_id | Card Payment Gateway ID |
cardname | Card holder name |
card_contact_id | Client contact ID to be used as billing contact for this card |
as_token | Set to 1 if its payment token but not related to credit card. Payment tokens cannot be primary. |
# Request
GET /admin/api.php?api_id=API_ID&api_key=API_KEY&call=addClientCreditCard&id=ID&cardnum=CARDNUM&cardtype=CARDTYPE&expiryyear=EXPIRYYEAR&expirymonth=EXPIRYMONTH
# PHP Samples
$url = 'http://url_to_hb.com/admin/api.php';
$post = [
'call' => 'addClientCreditCard',
'api_id' => $API_ID,
'api_key' => $API_KEY,
'id' => $ID,
'cardnum' => $CARDNUM,
'cardtype' => $CARDTYPE,
'expiryyear' => $EXPIRYYEAR,
'expirymonth' => $EXPIRYMONTH,
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$data = curl_exec($ch);
curl_close($ch);
$return = json_decode($data, true);
print_r($return);
include 'class.hbwrapper.php';
HBWrapper::setAPI('http://url_to_hb.com/admin/api.php','API ID','API Key');
$params = [
'id' => $ID,
'cardnum' => $CARDNUM,
'cardtype' => $CARDTYPE,
'expiryyear' => $EXPIRYYEAR,
'expirymonth' => $EXPIRYMONTH,
];
$return = HBWrapper::singleton()->addClientCreditCard($params);
print_r($return);
/* Use this method to access HostBill api from HostBill modules */
$api = new ApiWrapper();
$params = [
'id' => $ID,
'cardnum' => $CARDNUM,
'cardtype' => $CARDTYPE,
'expiryyear' => $EXPIRYYEAR,
'expirymonth' => $EXPIRYMONTH,
];
$return = $api->addClientCreditCard($params);
print_r($return);
# Response
{
"success": true,
"card_id": 85,
"call": "addClientCreditCard",
"server_time": 1662725447,
"info": [
"Client credit card has been added!"
]
}