Retrieve installment information
Overview
Use the getInstallments method to retrieve information about the number of installments available for a specific selection of product/services.
Supported payment methods
Credit/Debit cards: local Visa and MasterCard Brazilian cards.
Parameters
Parameters |
Type/Description |
sessionID |
Required (string) |
|
Session identifier, the output of the Login method. Include sessionID into all your requests. Avangate throws an exception if the values are incorrect. The sessionID expires in 10 minutes. |
Required (Object) |
|
|
Object designed to collect all data necessary for an order, including billing, product/subscription plan and payment details. |
Response
Attributes | Type/Description | |
InstallmentsOption |
Array of objects |
|
|
Details below. |
|
|
Number |
Int |
|
|
Number of installments. |
|
Amount |
Double |
|
|
Standalone installment value. (Total order value/Number of installments) |
|
Currency |
String |
|
|
Order currency. |
Request
<?php function callRPC($Request, $hostUrl, $Debug = true) { $curl = curl_init($hostUrl); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($curl, CURLOPT_SSLVERSION, 0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Accept: application/json')); $RequestString = json_encode($Request); curl_setopt($curl, CURLOPT_POSTFIELDS, $RequestString); if ($Debug) { $RequestString; } $ResponseString = curl_exec($curl); if ($Debug) { $ResponseString; } if (!empty($ResponseString)) { $Response = json_decode($ResponseString); if (isset($Response->result)) { return $Response->result; } if (!is_null($Response->error)) { var_dump($Request->method, $Response->error); } } else { return null; } } $host = 'https://api.avangate.com/rpc/3.0/'; $merchantCode = "MERCHANT_CODE";// your account's merchant code available in the 'System settings' area of the cPanel: https://secure.avangate.com/cpanel/account_settings.php $key = "SECRET_KEY";// your account's secret key available in the 'System settings' area of the cPanel: https://secure.avangate.com/cpanel/account_settings.php $string = strlen($merchantCode) . $merchantCode . strlen(gmdate('Y-m-d H:i:s')) . gmdate('Y-m-d H:i:s'); $hash = hash_hmac('md5', $string, $key); $i = 1; // counter for api calls // call login $jsonRpcRequest = new stdClass(); $jsonRpcRequest->jsonrpc = '2.0'; $jsonRpcRequest->method = 'login'; $jsonRpcRequest->params = array($merchantCode, gmdate('Y-m-d H:i:s'), $hash); $jsonRpcRequest->id = $i++; $sessionID = callRPC($jsonRpcRequest, $host); $Order = new stdClass(); $Order->RefNo = null; $Order->Currency = 'brl'; $Order->Country = 'BR'; $Order->Language = 'en'; $Order->CustomerIP = '91.220.121.21'; $Order->ExternalReference = null; $Order->Source = null; $Order->AffiliateId = null; $Order->CustomerReference = null; $Order->Items = array(); $Order->Items[0] = new stdClass(); $Order->Items[0]->Code = 'my_subscription_1'; $Order->Items[0]->Quantity = 1; $Order->Items[0]->PriceOptions = null; $Order->Items[0]->SKU = null; $Order->Items[0]->Price = null; $Order->Items[0]->CrossSell = null; $Order->Items[0]->Trial = false; $Order->Items[0]->AdditionalFields = null; $Order->Items[0]->Promotion = null; $Order->BillingDetails = new stdClass(); $Order->BillingDetails->FirstName = 'FirstName'; $Order->BillingDetails->LastName = 'LastName'; $Order->BillingDetails->CountryCode = 'BR'; $Order->BillingDetails->State = 'DF'; $Order->BillingDetails->City = 'LA'; $Order->BillingDetails->Address1 = 'Address example'; $Order->BillingDetails->Address2 = null; $Order->BillingDetails->Zip = '70403-900'; $Order->BillingDetails->Email = 'customer@email.com'; $Order->BillingDetails->Phone = "556133127400"; $Order->BillingDetails->FiscalCode = "056.027.963-98"; $Order->BillingDetails->Company = null; $Order->DeliveryDetails = null; $Order->PaymentDetails = new stdClass (); $Order->PaymentDetails->Type = 'CC'; $Order->PaymentDetails->Currency = 'brl'; $Order->PaymentDetails->PaymentMethod = new stdClass (); $Order->PaymentDetails->CustomerIP = '10.10.10.10'; $Order->PaymentDetails->PaymentMethod->RecurringEnabled = true; $Order->PaymentDetails->PaymentMethod->CardNumber = "4111111111111111"; $Order->PaymentDetails->PaymentMethod->CardType = 'visa'; $Order->PaymentDetails->PaymentMethod->ExpirationYear = '2019'; $Order->PaymentDetails->PaymentMethod->ExpirationMonth = '12'; $Order->PaymentDetails->PaymentMethod->HolderName = 'John'; $Order->PaymentDetails->PaymentMethod->CCID = '123'; $Order->Promotions = null; $Order->AdditionalFields = null; $Order->LocalTime = null; $Order->GiftDetails = null; $jsonRpcRequest = array ( 'method' => 'getInstallments', 'params' => array($sessionID, $Order), 'id' => $i++, 'jsonrpc' => '2.0' ); echo '<BR>'; echo 'The content of the current session:'; echo '<BR>'; $installments = callRPC((Object)$jsonRpcRequest, $host, true); var_dump ($installments); ?>