22
33namespace Omnipay \Gomypay \Tests ;
44
5+ use Omnipay \Common \Message \NotificationInterface ;
56use Omnipay \Gomypay \Gateway ;
7+ use Omnipay \Gomypay \PaymentMethod ;
68use Omnipay \Tests \GatewayTestCase ;
79
810class GatewayTest extends GatewayTestCase
@@ -18,27 +20,131 @@ public function setUp(): void
1820
1921 $ this ->gateway = new Gateway ($ this ->getHttpClient (), $ this ->getHttpRequest ());
2022 $ this ->gateway ->initialize ([
21- 'CustomerId ' => '2020050701 ' ,
23+ 'CustomerId ' => '80013554 ' ,
2224 'Str_Check ' => '2b1bef9d8ab6a81e9a2739c6ecc64ef8 ' ,
2325 'testMode ' => true ,
2426 ]);
27+ }
28+
29+ public function testPurchase ()
30+ {
31+ $ response = $ this ->gateway ->purchase ([
32+ 'transaction_id ' => '2020050701 ' ,
33+ 'amount ' => '1000 ' ,
34+ 'description ' => 'good to drink ' ,
35+ 'payment_method ' => PaymentMethod::CREDIT_CARD ,
36+ 'return_url ' => 'https://foo.bar/return_url ' ,
37+ 'notify_url ' => 'https://foo.bar/callback_url ' ,
2538
26- $ this ->options = [
27- 'amount ' => '10.00 ' ,
28- 'card ' => $ this ->getValidCard (),
29- ];
39+ 'buyer_name ' => 'foo ' ,
40+ 'buyer_telm ' => '0912345678 ' ,
41+ 'buyer_mail ' => 'foo@bar.com ' ,
42+ ])->send ();
43+
44+ $ this ->assertFalse ($ response ->isSuccessful ());
45+ $ this ->assertEquals ('https://n.gomypay.asia/TestShuntClass.aspx ' , $ response ->getRedirectUrl ());
46+ $ this ->assertEquals ('POST ' , $ response ->getRedirectMethod ());
47+ $ this ->assertEquals ('2020050701 ' , $ response ->getTransactionId ());
48+
49+ $ this ->assertEquals ([
50+ 'Send_Type ' => PaymentMethod::CREDIT_CARD ,
51+ 'Pay_Mode_No ' => 2 ,
52+ 'CustomerId ' => '80013554 ' ,
53+ 'Order_No ' => '2020050701 ' ,
54+ 'Amount ' => '1000 ' ,
55+ 'TransCode ' => '00 ' ,
56+ 'Buyer_Name ' => 'foo ' ,
57+ 'Buyer_Telm ' => '0912345678 ' ,
58+ 'Buyer_Mail ' => 'foo@bar.com ' ,
59+ 'Buyer_Memo ' => 'good to drink ' ,
60+ 'TransMode ' => 1 ,
61+ 'Installment ' => 0 ,
62+ 'Return_url ' => 'https://foo.bar/return_url ' ,
63+ 'Callback_Url ' => 'https://foo.bar/callback_url ' ,
64+ ], $ response ->getData ());
3065 }
3166
32- public function testAuthorize ()
67+ public function testCompletePurchase ()
3368 {
34- $ this ->markTestSkipped ();
69+ $ this ->getHttpRequest ()->query ->replace ([
70+ 'Send_Type ' => '0 ' ,
71+ 'result ' => '1 ' ,
72+ 'ret_msg ' => '授權成功 ' ,
73+ 'OrderID ' => '2020050700000000001 ' ,
74+ 'e_orderno ' => '2020050701 ' ,
75+ 'AvCode ' => '012345 ' ,
76+ 'str_check ' => 'bf577c7a76d440a797c1716aff9c01c9 ' ,
77+ 'Invoice_No ' => '12345 ' ,
78+ 'CardLastNum ' => '2222 ' ,
79+ ]);
3580
36- $ this ->setMockHttpResponse ( ' AuthorizeSuccess.txt ' );
81+ $ response = $ this ->gateway -> completePurchase ([ ' amount ' => ' 50 ' ])-> send ( );
3782
38- $ response = $ this ->gateway ->purchase ($ this ->options )->send ();
83+ $ this ->assertTrue ($ response ->isSuccessful ());
84+ $ this ->assertEquals ('授權成功 ' , $ response ->getMessage ());
85+ $ this ->assertEquals ('1 ' , $ response ->getCode ());
86+ $ this ->assertEquals ('2020050701 ' , $ response ->getTransactionId ());
87+ $ this ->assertEquals ('2020050700000000001 ' , $ response ->getTransactionReference ());
88+ }
89+
90+ public function testAcceptNotification ()
91+ {
92+ $ this ->getHttpRequest ()->request ->replace ([
93+ 'Send_Type ' => '6 ' ,
94+ 'StoreType ' => '3 ' ,
95+ 'result ' => '1 ' ,
96+ 'ret_msg ' => '已繳費 ' ,
97+ 'OrderID ' => '2020050700000000001 ' ,
98+ 'e_money ' => '100 ' ,
99+ 'PayAmount ' => '50 ' ,
100+ 'e_date ' => '20200507 ' ,
101+ 'e_time ' => '12:30:59 ' ,
102+ 'e_orderno ' => '2020050701 ' ,
103+ 'PinCode ' => 'GMPA2018383076 ' ,
104+ 'Barcode2 ' => '123456 ' ,
105+ 'Market_ID ' => 'SE ' ,
106+ 'Shop_Store_Name ' => '7-11(地址) ' ,
107+ 'str_check ' => 'bf577c7a76d440a797c1716aff9c01c9 ' ,
108+ ]);
109+
110+ $ request = $ this ->gateway ->acceptNotification (['amount ' => '50 ' ]);
111+
112+ $ this ->assertEquals (NotificationInterface::STATUS_COMPLETED , $ request ->getTransactionStatus ());
113+ $ this ->assertEquals ('已繳費 ' , $ request ->getMessage ());
114+ $ this ->assertEquals ('2020050701 ' , $ request ->getTransactionId ());
115+ $ this ->assertEquals ('2020050700000000001 ' , $ request ->getTransactionReference ());
116+ }
117+
118+ public function testFetchTransaction ()
119+ {
120+ $ this ->setMockHttpResponse ('FetchTransactionSuccess.txt ' );
121+ $ response = $ this ->gateway ->fetchTransaction (['transaction_id ' => 'AH15482399052114 ' ])->send ();
39122
40123 $ this ->assertTrue ($ response ->isSuccessful ());
41- $ this ->assertEquals ('1234 ' , $ response ->getTransactionReference ());
42- $ this ->assertNull ($ response ->getMessage ());
124+ $ this ->assertEquals ('已繳費 ' , $ response ->getMessage ());
125+ $ this ->assertEquals ('1 ' , $ response ->getCode ());
126+ $ this ->assertEquals ('AH15482399052114 ' , $ response ->getTransactionId ());
127+ $ this ->assertEquals ('2019012300000000569 ' , $ response ->getTransactionReference ());
128+ }
129+
130+ public function testGetPaymentInfo ()
131+ {
132+ $ this ->getHttpRequest ()->query ->replace ([
133+ 'Send_Type ' => '4 ' ,
134+ 'result ' => '1 ' ,
135+ 'OrderID ' => '2020050700000000001 ' ,
136+ 'e_orderno ' => '2020050701 ' ,
137+ 'e_payaccount ' => '013 - 國泰世華 - 0055600701508856 ' ,
138+ 'LimitDate ' => '2020/07/01 ' ,
139+ 'ret_msg ' => '取號成功 ' ,
140+ 'str_check ' => 'bf577c7a76d440a797c1716aff9c01c9 ' ,
141+ ]);
142+ $ response = $ this ->gateway ->getPaymentInfo (['amount ' => '50 ' ])->send ();
143+
144+ $ this ->assertFalse ($ response ->isSuccessful ());
145+ $ this ->assertEquals ('取號成功 ' , $ response ->getMessage ());
146+ $ this ->assertEquals ('1 ' , $ response ->getCode ());
147+ $ this ->assertEquals ('2020050701 ' , $ response ->getTransactionId ());
148+ $ this ->assertEquals ('2020050700000000001 ' , $ response ->getTransactionReference ());
43149 }
44150}
0 commit comments