Skip to content

Commit 19236dd

Browse files
committed
Added new samples and modified CybsSoapClient::createRequest() to accept the merchant reference code
1 parent 75f1520 commit 19236dd

4 files changed

Lines changed: 141 additions & 1 deletion

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
/composer.phar
66
/composer.lock
77

8+
# CyberSource config parameters
9+
/lib/conf/cybs.ini

lib/CybsSoapClient.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,18 @@ public function getTransactionKey()
105105
}
106106

107107
/**
108+
* @param string The desired reference code for this request.
108109
*
109110
* @return stdClass An object initialized with the client's merchant ID.
110111
*/
111-
public function createRequest()
112+
public function createRequest($merchantReferenceCode)
112113
{
113114
$request = new stdClass();
114115
$request->merchantID = $this->merchantId;
116+
$request->merchantReferenceCode = $merchantReferenceCode;
117+
$request->clientLibrary = "PHP";
118+
$request->clientLibraryVersion = phpversion();
119+
$request->clientEnvironment = php_uname();
115120
return $request;
116121
}
117122
}

samples/AuthCapture.php

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
// This sample demonstrates how to run an authorization request followed by a
3+
// capture request.
4+
5+
// Using Composer-generated autoload file.
6+
require 'vendor/autoload.php';
7+
// Or, uncomment the line below if you're not using Composer autoloader.
8+
// require_once('lib/CybsSoapClient.php');
9+
10+
11+
// Before using this example, you can use your own reference code for the transaction.
12+
$referenceCode = 'your_merchant_reference_code';
13+
14+
$client = new CybsSoapClient();
15+
$request = $client->createRequest($referenceCode);
16+
17+
// This section contains a sample transaction request for the authorization
18+
// service with complete billing, payment card, and purchase (two items) information.
19+
$ccAuthService = new stdClass();
20+
$ccAuthService->run = 'true';
21+
$request->ccAuthService = $ccAuthService;
22+
23+
$billTo = new stdClass();
24+
$billTo->firstName = 'John';
25+
$billTo->lastName = 'Doe';
26+
$billTo->street1 = '1295 Charleston Road';
27+
$billTo->city = 'Mountain View';
28+
$billTo->state = 'CA';
29+
$billTo->postalCode = '94043';
30+
$billTo->country = 'US';
31+
$billTo->email = 'null@cybersource.com';
32+
$billTo->ipAddress = '10.7.111.111';
33+
$request->billTo = $billTo;
34+
35+
$card = new stdClass();
36+
$card->accountNumber = '4111111111111111';
37+
$card->expirationMonth = '12';
38+
$card->expirationYear = '2020';
39+
$request->card = $card;
40+
41+
$purchaseTotals = new stdClass();
42+
$purchaseTotals->currency = 'USD';
43+
$request->purchaseTotals = $purchaseTotals;
44+
45+
$item0 = new stdClass();
46+
$item0->unitPrice = '12.34';
47+
$item0->quantity = '2';
48+
$item0->id = '0';
49+
50+
$item1 = new stdClass();
51+
$item1->unitPrice = '56.78';
52+
$item1->id = '1';
53+
54+
$request->item = array($item0, $item1);
55+
56+
$reply = $client->runTransaction($request);
57+
58+
// This section will show all the reply fields.
59+
print("\nAUTH RESPONSE: " . print_r($reply, true));
60+
61+
if ($reply->decision != 'ACCEPT') {
62+
print("\nFailed auth request.\n");
63+
return;
64+
}
65+
66+
// Build a capture using the request ID in the response as the auth request ID
67+
$ccCaptureService = new stdClass();
68+
$ccCaptureService->run = 'true';
69+
$ccCaptureService->authRequestID = $reply->requestID;
70+
71+
$captureRequest = $client->createRequest($referenceCode);
72+
$captureRequest->ccCaptureService = $ccCaptureService;
73+
$captureRequest->item = array($item0, $item1);
74+
$captureRequest->purchaseTotals = $purchaseTotals;
75+
76+
$captureReply = $client->runTransaction($captureRequest);
77+
78+
// This section will show all the reply fields.
79+
print("\nCAPTRUE RESPONSE: " . print_r($captureReply, true));

samples/Sale.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
// This sample demonstrates how to run a sale request, which combines an
3+
// authorization with a capture in one request.
4+
5+
// Using Composer-generated autoload file.
6+
require 'vendor/autoload.php';
7+
8+
// Or, uncomment the line below if you're not using Composer autoloader.
9+
// require_once('lib/CybsSoapClient.php');
10+
11+
12+
// Before using this example, you can use your own reference code for the transaction.
13+
$referenceCode = 'your_merchant_reference_code';
14+
15+
$client = new CybsSoapClient();
16+
$request = $client->createRequest($referenceCode);
17+
18+
// Build a sale request (combining an auth and capture). In this example only
19+
// the amount is provided for the purchase total.
20+
$ccAuthService = new stdClass();
21+
$ccAuthService->run = 'true';
22+
$request->ccAuthService = $ccAuthService;
23+
24+
$ccCaptureService = new stdClass();
25+
$ccCaptureService->run = 'true';
26+
$request->ccCaptureService = $ccCaptureService;
27+
28+
$billTo = new stdClass();
29+
$billTo->firstName = 'John';
30+
$billTo->lastName = 'Doe';
31+
$billTo->street1 = '1295 Charleston Road';
32+
$billTo->city = 'Mountain View';
33+
$billTo->state = 'CA';
34+
$billTo->postalCode = '94043';
35+
$billTo->country = 'US';
36+
$billTo->email = 'null@cybersource.com';
37+
$billTo->ipAddress = '10.7.111.111';
38+
$request->billTo = $billTo;
39+
40+
$card = new stdClass();
41+
$card->accountNumber = '4111111111111111';
42+
$card->expirationMonth = '12';
43+
$card->expirationYear = '2020';
44+
$request->card = $card;
45+
46+
$purchaseTotals = new stdClass();
47+
$purchaseTotals->currency = 'USD';
48+
$purchaseTotals->grandTotalAmount = '90.01';
49+
$request->purchaseTotals = $purchaseTotals;
50+
51+
$reply = $client->runTransaction($request);
52+
53+
// This section will show all the reply fields.
54+
print("\nRESPONSE: " . print_r($reply, true));

0 commit comments

Comments
 (0)