|
| 1 | +<?php |
| 2 | +// This sample demonstrates how to create a subscription |
| 3 | + |
| 4 | +// Using Composer-generated autoload file. |
| 5 | +require __DIR__ . '/../vendor/autoload.php'; |
| 6 | +// Or, uncomment the line below if you're not using Composer autoloader. |
| 7 | +// require_once(__DIR__ . '/../lib/CybsSoapClient.php'); |
| 8 | + |
| 9 | + |
| 10 | +// Before using this example, you can use your own reference code for the transaction. |
| 11 | +$referenceCode = 'your_merchant_reference_code'; |
| 12 | + |
| 13 | +$client = new CybsSoapClient(); |
| 14 | +$request = $client->createRequest($referenceCode); |
| 15 | + |
| 16 | +// This section contains a sample transaction request for creating a subscription |
| 17 | + |
| 18 | +$paySubscriptionCreateService = new stdClass(); |
| 19 | +$paySubscriptionCreateService->run = 'true'; |
| 20 | +$request->paySubscriptionCreateService = $paySubscriptionCreateService; |
| 21 | + |
| 22 | +$billTo = new stdClass(); |
| 23 | +$billTo->firstName = 'John'; |
| 24 | +$billTo->lastName = 'Doe'; |
| 25 | +$billTo->street1 = '1295 Charleston Road'; |
| 26 | +$billTo->city = 'Mountain View'; |
| 27 | +$billTo->state = 'CA'; |
| 28 | +$billTo->postalCode = '94043'; |
| 29 | +$billTo->country = 'US'; |
| 30 | +$billTo->email = 'null@cybersource.com'; |
| 31 | +$billTo->ipAddress = '10.7.111.111'; |
| 32 | +$request->billTo = $billTo; |
| 33 | + |
| 34 | +$card = new stdClass(); |
| 35 | +$card->accountNumber = '4111111111111111'; |
| 36 | +$card->expirationMonth = '12'; |
| 37 | +$card->expirationYear = '2020'; |
| 38 | +$card->cardType='001'; |
| 39 | +$request->card = $card; |
| 40 | + |
| 41 | +$purchaseTotals = new stdClass(); |
| 42 | +$purchaseTotals->currency = 'USD'; |
| 43 | +$request->purchaseTotals = $purchaseTotals; |
| 44 | + |
| 45 | +$recurringSubscriptionInfo = new stdClass(); |
| 46 | +$recurringSubscriptionInfo->frequency = 'monthly'; |
| 47 | +$recurringSubscriptionInfo->amount = '11.00'; |
| 48 | +$recurringSubscriptionInfo->automaticRenew = 'false'; |
| 49 | +$recurringSubscriptionInfo->numberOfPayments = '4'; |
| 50 | +$recurringSubscriptionInfo->startDate = '20140221'; |
| 51 | + |
| 52 | +$request->recurringSubscriptionInfo = $recurringSubscriptionInfo; |
| 53 | + |
| 54 | +$reply = $client->runTransaction($request); |
| 55 | + |
| 56 | +// This section will show all the reply fields. |
| 57 | +print("\nSUBSCRIPTION RESPONSE: " . print_r($reply, true)); |
| 58 | + |
| 59 | +if ($reply->decision != 'ACCEPT') { |
| 60 | + print("\nFailed subscription request.\n"); |
| 61 | + return; |
| 62 | +} |
| 63 | +else |
| 64 | +{ |
| 65 | + print("\n Subscription service request successful\n"); |
| 66 | +} |
0 commit comments