How to create Subscriptions in cybersource Payment Gateway

| By Webner

Basically subscription in Cybersource is the customer profile that holds its details like customer details, billing and shipping details, customer payment information like card type, expiration date, account number etc. We have to pass all these details to Cybersource with an API call and corresponding to that request cybersource will give us the response whether the subscription is created successfully or not. For every subscription cybersource provides the unique subscription ID which is also known as payment token which can be used to retrieve, cancel or delete that subscription. It is unique for every subscription created. Using that we can also update or charge the subscription.

Below is the example in which we are requesting cybersource to create a customer subscription:

$request->merchant_id = ‘abcd’;
$request->transaction_key = ‘34hbjh4nbn4h4b’;		
$request->environment = ‘’;

$cardNumber = 4111111111111111;
$expiration_month = 12;
$expiration_year = 2019;
$cvvNumber =1234;
$card_type = ‘Visa;

$request->card( $cardNumber, $expiration_month, $expiration_year, $cvvNumber, $card_type); $request- ->bill_to( array(
  				 'firstName' => ‘abc’,
  				 'lastName' =>’xyz’,
  				 'street1' => 'test',
  				 'city' => 'test',
  				 'state' => 'test',
  				 'postalCode' => '111111',
  				 'country' => 'India',
  				 'email' => '',
  		 ) );

$subscription_create = new \stdClass();
$subscription_create->run = 'true';

$request->paySubscriptionCreateService = $subscription_create;

   // specify that this is an on-demand subscription, it should not auto-bill
$subscription_info = new \stdClass();
$subscription_info->frequency = 'on-demand';
$subscription_info->amount = 100;
$subscription_info->startDate = 09082017;

$request->recurringSubscriptionInfo = $subscription_info;
$response = $this->run_transaction( $request );

Leave a Reply

Your email address will not be published. Required fields are marked *