Update subscription payment information
Use the updateSubscriptionPaymentInformation method to update the credit card information related to the payment to be made for a subscription. To be able to do this, you need to generate a payment token using the credit card information via the 2Pay.js library, and then use this token in the request of the method as indicated below.
Request parameters
sessionID
String
Required
The 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.
subscriptionReference
String
Required
The reference of the subscription for which you want to retrieve the payment information.
paymentInformation
Object
Required
The payment information object, details below:
PaymentDetails
Object
Required
The payment details object, details below:
Type
String
Required
The payment details type. Restricted to EES_TOKEN_PAYMENT for now.
PaymentMethod
Object
Required
The payment method object, details below:
EesToken
String
Required
The 2Pay token obtained by integrating the 2Pay.js library.
Vendor3DSReturnURL
String
Required
URL address to which customers are redirected after the 3DS details get validated by the bank and the order is successfully authorized.
Vendor3DSCancelURL
String
Required
URL address to which customers are redirected after the 3DS details get validated by the bank and the order is successfully authorized.
Request example
<?php
declare(strict_types=1);
class Configuration
{
public const MERCHANT_CODE = '';
public const MERCHANT_KEY = '';
public const URL = 'http://api.2checkout.com/soap/6.0';
public const ACTION = 'updateSubscriptionPaymentInformation';
public const ADDITIONAL_OPTIONS = null;
public const SUBSCRIPTION_REF = 'YC9XXMGOYO';
//array or JSON
public const PAYLOAD = <<<JSON
{
"PaymentDetails": {
"Type": "EES_TOKEN_PAYMENT",
"PaymentMethod": {
"EesToken": "f6347256-bbbb-45a8-be61-e21fe1725f47",
"Vendor3DSReturnURL": "www.3dsReturnURL.com",
"Vendor3DSCancelURL": "www.3dsCancelURL.com"
}
}
}
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, Configuration::SUBSCRIPTION_REF, $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;
$hash = hash_hmac('md5', $string, $key);
// $client->__setCookie('XDEBUG_SESSION', 'PHPSTORM');
return $client->login($merchantCode, $date, $hash);
}
}
try {
$client = new Client();
var_dump($client->call());
} catch (Exception $ex) {
var_dump($ex);
}Response
The method responds with Boolean True when the payment information update was successfully performed.
Otherwise, in case of validation or access rights failures, it returns the usual error response with specific messages indicating the cause of the failure.
Last updated
Was this helpful?