1+ <?php
2+
3+ namespace Omnipay \Beanstream \tests ;
4+
5+ use Omnipay \Beanstream \Gateway ;
6+ use Omnipay \Tests \GatewayTestCase ;
7+
8+ /**
9+ * Class IntegrationTest
10+ *
11+ * This is an integration test class so it actually sends messages to Beanstream. This means you will need to setup a
12+ * test account with them and get your Merchant ID and API Passcode. Once you have those, you can create a new file in
13+ * the Mock folder called myCredentials.json and format it as below:
14+ *
15+ * {
16+ * "merchantId":"<Your Merchant ID here>",
17+ * "apiPasscode":"<Your Passcode here>"
18+ * }
19+ *
20+ * If that file does not exist or is not formatted in this way, all tests in this class will be skipped.
21+ *
22+ * @package Omnipay\Beanstream\tests
23+ */
24+ class IntegrationTest extends GatewayTestCase
25+ {
26+ /** @var Gateway */
27+ protected $ gateway ;
28+
29+ /**
30+ * Check for the credentials file. Skips the test if the credentials file is missing or not setup correctly. Otherwise,
31+ * instantiates the gateway and sets up the credentials.
32+ */
33+ public function setUp ()
34+ {
35+ $ merchantId = '' ;
36+ $ apiPasscode = '' ;
37+ $ credentialsFilePath = dirname (__FILE__ ) . '/Mock/myCredentials.json ' ;
38+
39+ if (file_exists ($ credentialsFilePath )) {
40+ $ credentialsJson = file_get_contents ($ credentialsFilePath );
41+ if ($ credentialsJson ) {
42+ $ credentials = json_decode ($ credentialsJson );
43+ $ merchantId = $ credentials ->merchantId ;
44+ $ apiPasscode = $ credentials ->apiPasscode ;
45+ }
46+ }
47+
48+ if (empty ($ merchantId ) || empty ($ apiPasscode )) {
49+ $ this ->markTestSkipped ();
50+ } else {
51+ $ this ->gateway = new Gateway ();
52+ $ this ->gateway ->setMerchantId ($ merchantId );
53+ $ this ->gateway ->setApiPasscode ($ apiPasscode );
54+ }
55+ }
56+
57+ /**
58+ * Test an Authorize call followed by a capture call for that transaction
59+ */
60+ public function testAuthCapture ()
61+ {
62+ $ card = $ this ->getValidCard ();
63+ $ card ['number ' ] = '4030000010001234 ' ;
64+ $ card ['cvv ' ] = '123 ' ;
65+ $ authResponse = $ this ->gateway ->authorize (
66+ array (
67+ 'amount ' =>10.00 ,
68+ 'card ' =>$ card ,
69+ 'payment_method ' =>'card '
70+ )
71+ )->send ();
72+ $ this ->assertTrue ($ authResponse ->isSuccessful ());
73+ $ this ->assertSame ('Approved ' , $ authResponse ->getMessage ());
74+
75+ $ captureResponse = $ this ->gateway ->capture (
76+ array (
77+ 'transactionReference ' =>$ authResponse ->getTransactionReference (),
78+ 'amount ' =>10.00
79+ )
80+ )->send ();
81+
82+ $ this ->assertTrue ($ captureResponse ->isSuccessful ());
83+ $ this ->assertSame ('Approved ' , $ captureResponse ->getMessage ());
84+ }
85+
86+ /**
87+ * Test a failed purchase transaction. The card number used below is a special one for Beanstream that always declines.
88+ */
89+ public function testFailedPurchase ()
90+ {
91+ $ card = $ this ->getValidCard ();
92+ $ card ['number ' ] = '4003050500040005 ' ;
93+ $ card ['cvv ' ] = '123 ' ;
94+ $ purchaseResponse = $ this ->gateway ->purchase (
95+ array (
96+ 'amount ' =>10.00 ,
97+ 'card ' =>$ card ,
98+ 'payment_method ' =>'card '
99+ )
100+ )->send ();
101+
102+ $ this ->assertFalse ($ purchaseResponse ->isSuccessful ());
103+ $ this ->assertSame ('DECLINE ' , $ purchaseResponse ->getMessage ());
104+ }
105+
106+ /**
107+ * Test a purchase call followed by a refund call for that purchase
108+ */
109+ public function testPurchaseRefund ()
110+ {
111+ $ card = $ this ->getValidCard ();
112+ $ card ['number ' ] = '4030000010001234 ' ;
113+ $ card ['cvv ' ] = '123 ' ;
114+ $ purchaseResponse = $ this ->gateway ->purchase (
115+ array (
116+ 'amount ' =>20.00 ,
117+ 'card ' =>$ card ,
118+ 'payment_method ' =>'card '
119+ )
120+ )->send ();
121+
122+ $ this ->assertTrue ($ purchaseResponse ->isSuccessful ());
123+ $ this ->assertSame ('Approved ' , $ purchaseResponse ->getMessage ());
124+
125+ $ refundResponse = $ this ->gateway ->refund (
126+ array (
127+ 'amount ' =>20.00 ,
128+ 'transactionReference ' =>$ purchaseResponse ->getTransactionReference ()
129+ )
130+ )->send ();
131+
132+ $ this ->assertTrue ($ refundResponse ->isSuccessful ());
133+ $ this ->assertSame ('Approved ' , $ refundResponse ->getMessage ());
134+ }
135+
136+ /**
137+ * Test a purchase call followed by a void call for that purchase
138+ */
139+ public function testPurchaseVoid ()
140+ {
141+ $ card = $ this ->getValidCard ();
142+ $ card ['number ' ] = '4030000010001234 ' ;
143+ $ card ['cvv ' ] = '123 ' ;
144+ $ purchaseResponse = $ this ->gateway ->purchase (
145+ array (
146+ 'amount ' =>20.00 ,
147+ 'card ' =>$ card ,
148+ 'payment_method ' =>'card '
149+ )
150+ )->send ();
151+
152+ $ this ->assertTrue ($ purchaseResponse ->isSuccessful ());
153+ $ this ->assertSame ('Approved ' , $ purchaseResponse ->getMessage ());
154+
155+ $ voidResponse = $ this ->gateway ->void (
156+ array (
157+ 'amount ' =>20.00 ,
158+ 'transactionReference ' =>$ purchaseResponse ->getTransactionReference ()
159+ )
160+ )->send ();
161+
162+ $ this ->assertTrue ($ voidResponse ->isSuccessful ());
163+ $ this ->assertSame ('Approved ' , $ voidResponse ->getMessage ());
164+ }
165+ }
0 commit comments