Use Stored Credit
Overview
The Stored Credit payment method allows merchants to process payments without requiring payment details from the shopper. Instead, the shopper's credit balance is pre-stored and managed within your system (NOT stored by 2Checkout). When using this payment method via API, it is the merchant's responsibility to validate that the shopper has sufficient credits to complete the transaction. This method allows you to accept payments using pre-purchased credits systems such as proprietary gift vouchers.
Availability
This payment method is exclusive to the API and is not available on any of 2Checkout's hosted shopping carts.
Supported currencies
Stored Credit supports all billing currencies accepted by 2Checkout.
Workflow
- Distribute the credits to your customers using your desired process, outside of the 2Checkout platform.
- Validate that the customer who intends to initiate the order has enough credits available.
-
Create the order object. Use STORED_CREDIT as the type in PaymentDetails object.
It is not recommended that you use the PaymentMethod object for Stored Credit, the only parameter supported is RecurringEnabled = false which is also the default value, true is not supported and will return an error. - Place the order.
Request parameters
Parameters | Type/Description |
---|---|
sessionID |
Required (string) Session identifier, the output of the Login method. Include sessionID into all your requests. 2Checkout throws an exception if the values are incorrect. The sessionID expires in 10 minutes. |
Order |
Required (object) Object designed to collect all data necessary for an order, including billing, product/subscription plan and payment details. See code sample for more details. |
Request example
<?php
declare(strict_types=1);
class Configuration
{
public const MERCHANT_CODE = 'MERCHANT';
public const MERCHANT_KEY = 'SECRET_KEY';
public const URL = 'https://api.2checkout.com/soap/6.0';
public const ACTION = 'placeOrder';
public const PAYLOAD = <<<JSON
{
"Currency": "USD",
"Language": "EN",
"Country": "us",
"CustomerIP": "91.220.121.21",
"Source": "sourceAPI.net",
"LocalTime": "2022-01-13 09:41:59",
"CustomerReference": 421820775,
"Items": [
{
"Code": "TA-TuneUp-M-RENEW"
}
],
"BillingDetails": {
"Address1": "Test Address",
"City": "LA",
"State": "California",
"CountryCode": "US",
"Email": "testcustomer@2Checkout.com",
"FirstName": "Customer",
"LastName": "2Checkout",
"Zip": "12345"
},
"PaymentDetails": {
"Type": "STORED_CREDIT",
"Currency": "USD",
"CustomerIP": "91.220.121.21"
}
}
JSON;
}
class Client
{
public function call(
string $url = Configuration::URL,
$payload = Configuration::PAYLOAD,
string $action = Configuration::ACTION
): ?object {
if (is_array($payload)) {
$payload = json_encode($payload);
}
if (!empty($payload)) {
// SoapClient works with objects(StdClass)
$payload = json_decode($payload);
}
$soapClient = $this->getClient($url);
$sessionId = $this->getSession($soapClient);
$args = array_filter([$sessionId, $payload]);
return $soapClient->$action(...$args);
}
public function getClient(string $url): SoapClient
{
return new SoapClient(
$url.'?wsdl',
[
'location' => $url,
'cache_wsdl' => WSDL_CACHE_NONE,
]
);
}
public function getSession(SoapClient $client)
{
$date = gmdate('Y-m-d H:i:s');
$merchantCode = Configuration::MERCHANT_CODE;
$key = Configuration::MERCHANT_KEY;
$string = strlen($merchantCode).$merchantCode.strlen($date).$date;
$algo = 'sha256';
$hash = hash_hmac($algo, $string, $key);
$client->__setCookie('XDEBUG_SESSION', 'PHPSTORM');
return $client->login($merchantCode, $date, $hash, $algo);
}
}
try {
$client = new Client();
var_dump($client->call());
} catch (Exception $ex) {
var_dump($ex);
}
Response parameters
Parameter | Type/Description |
---|---|
Order information | Object Object containing order information. |