@@ -28,12 +28,12 @@ public async void TestPaymentInfoValidationRules()
28
28
info . Validate ( ) ;
29
29
info . Amount = - 1 ;
30
30
await Assert . ThrowsAsync < ValidationException > ( async ( ) => await Task . Run ( ( ) => info . Validate ( ) ) ) ;
31
-
31
+
32
32
info = GetValidPaymentInfo ( ) ;
33
33
info . Validate ( ) ;
34
34
info . Source = null ;
35
35
await Assert . ThrowsAsync < ValidationException > ( async ( ) => await Task . Run ( ( ) => info . Validate ( ) ) ) ;
36
-
36
+
37
37
info = GetValidPaymentInfo ( ) ;
38
38
info . Validate ( ) ;
39
39
info . CallbackUrl = "hey" ;
@@ -47,26 +47,26 @@ public async void TestCcSourceValidationRules()
47
47
source . Validate ( ) ;
48
48
source . Name = "" ;
49
49
await Assert . ThrowsAsync < ValidationException > ( async ( ) => await Task . Run ( ( ) => source . Validate ( ) ) ) ;
50
-
50
+
51
51
source = GetValidCcSource ( ) ;
52
52
source . Validate ( ) ;
53
53
source . Number = "" ;
54
54
await Assert . ThrowsAsync < ValidationException > ( async ( ) => await Task . Run ( ( ) => source . Validate ( ) ) ) ;
55
-
55
+
56
56
source = GetValidCcSource ( ) ;
57
57
source . Validate ( ) ;
58
58
source . Cvc = 0 ;
59
59
await Assert . ThrowsAsync < ValidationException > ( async ( ) => await Task . Run ( ( ) => source . Validate ( ) ) ) ;
60
60
source . Cvc = 1000 ;
61
61
await Assert . ThrowsAsync < ValidationException > ( async ( ) => await Task . Run ( ( ) => source . Validate ( ) ) ) ;
62
-
62
+
63
63
source = GetValidCcSource ( ) ;
64
64
source . Validate ( ) ;
65
65
source . Month = 0 ;
66
66
await Assert . ThrowsAsync < ValidationException > ( async ( ) => await Task . Run ( ( ) => source . Validate ( ) ) ) ;
67
67
source . Month = 13 ;
68
68
await Assert . ThrowsAsync < ValidationException > ( async ( ) => await Task . Run ( ( ) => source . Validate ( ) ) ) ;
69
-
69
+
70
70
source = GetValidCcSource ( ) ;
71
71
source . Validate ( ) ;
72
72
source . Year = - 1 ;
@@ -77,7 +77,7 @@ public async void TestCcSourceValidationRules()
77
77
public void TestDeserializingPayment ( )
78
78
{
79
79
ServiceMockHelper . MockJsonResponse ( "Fixtures/CreditCard/Paid.json" ) ;
80
-
80
+
81
81
var payment = Payment . Fetch ( "b6c01c90-a091-45a4-9358-71668ecbf7ea" ) ;
82
82
Assert . Equal ( "b6c01c90-a091-45a4-9358-71668ecbf7ea" , payment . Id ) ;
83
83
Assert . Equal ( 1000 , payment . Amount ) ;
@@ -86,44 +86,48 @@ public void TestDeserializingPayment()
86
86
Assert . Equal ( "https://mystore.com/order/redirect-back" , payment . CallbackUrl ) ;
87
87
Assert . Equal ( "5c02ba44-7fd1-444c-b82b-d3993b87d4b0" , payment . Metadata [ "order_id" ] ) ;
88
88
Assert . Equal ( "50" , payment . Metadata [ "tax" ] ) ;
89
-
89
+
90
90
Assert . IsType < CreditCard > ( payment . Source ) ;
91
91
var ccSource = ( CreditCard ) payment . Source ;
92
-
92
+
93
93
Assert . Equal ( "Long John" , ccSource . Name ) ;
94
94
Assert . Equal ( "XXXX-XXXX-XXXX-1111" , ccSource . Number ) ;
95
+ Assert . Equal ( "moyasar_ap_je1iUidxhrh74257S891wvW" , ccSource . GatewayId ) ;
96
+ Assert . Equal ( "125478454231" , ccSource . ReferenceNumber ) ;
95
97
}
96
-
98
+
97
99
[ Fact ]
98
100
public void TestDeserializingApplePayPayment ( )
99
101
{
100
102
ServiceMockHelper . MockJsonResponse ( "Fixtures/ApplePay/Paid.json" ) ;
101
-
103
+
102
104
var payment = Payment . Fetch ( "a4a144ba-adc3-43bd-98e8-c80f2925fdc4" ) ;
103
105
Assert . Equal ( 1000 , payment . Amount ) ;
104
106
Assert . Equal ( "SAR" , payment . Currency ) ;
105
107
Assert . Equal ( "Test Payment" , payment . Description ) ;
106
108
Assert . Null ( payment . CallbackUrl ) ;
107
-
109
+
108
110
Assert . IsType < ApplePayMethod > ( payment . Source ) ;
109
111
var applePaySource = ( ApplePayMethod ) payment . Source ;
110
-
112
+
111
113
Assert . Equal ( "applepay" , applePaySource . Type ) ;
112
114
Assert . Equal ( "XXXX-XXXX-XXXX-1111" , applePaySource . Number ) ;
113
115
Assert . Equal ( "APPROVED" , applePaySource . Message ) ;
116
+ Assert . Equal ( "moyasar_ap_je1iUidxhrh74257S891wvW" , applePaySource . GatewayId ) ;
117
+ Assert . Equal ( "125478454231" , applePaySource . ReferenceNumber ) ;
114
118
}
115
-
119
+
116
120
[ Fact ]
117
121
public void TestDeserializingStcPayPayment ( )
118
122
{
119
123
ServiceMockHelper . MockJsonResponse ( "Fixtures/StcPay/Paid.json" ) ;
120
-
124
+
121
125
var payment = Payment . Fetch ( "50559d3b-e67f-4b3a-8df8-509dde19fe38" ) ;
122
126
Assert . Equal ( 1000 , payment . Amount ) ;
123
127
Assert . Equal ( "SAR" , payment . Currency ) ;
124
128
Assert . Equal ( "Test Payment" , payment . Description ) ;
125
129
Assert . Null ( payment . CallbackUrl ) ;
126
-
130
+
127
131
Assert . IsType < StcPayMethod > ( payment . Source ) ;
128
132
var method = ( StcPayMethod ) payment . Source ;
129
133
Assert . Equal ( "stcpay" , method . Type ) ;
@@ -135,30 +139,30 @@ public void TestDeserializingStcPayPayment()
135
139
public void TestRefundPayment ( )
136
140
{
137
141
ServiceMockHelper . MockJsonResponse ( "Fixtures/CreditCard/Paid.json" ) ;
138
-
142
+
139
143
var payment = Payment . Fetch ( "b6c01c90-a091-45a4-9358-71668ecbf7ea" ) ;
140
144
var id = payment . Id ;
141
145
var amount = payment . Amount ;
142
-
146
+
143
147
ServiceMockHelper . MockJsonResponse ( "Fixtures/CreditCard/Refunded.json" ) ;
144
148
145
149
payment . Refund ( ) ;
146
-
150
+
147
151
Assert . Equal ( id , payment . Id ) ;
148
152
Assert . Equal ( "refunded" , payment . Status ) ;
149
153
Assert . Equal ( amount , payment . RefundedAmount ) ;
150
154
Assert . Equal ( DateTime . Parse ( "2019-01-03T10:14:14.414Z" ) . ToUniversalTime ( ) , payment . RefundedAt ) ;
151
155
}
152
-
156
+
153
157
[ Fact ]
154
158
public async void RefundHigherAmountMustThrowException ( )
155
159
{
156
160
ServiceMockHelper . MockJsonResponse ( "Fixtures/CreditCard/Paid.json" ) ;
157
-
161
+
158
162
var payment = Payment . Fetch ( "b6c01c90-a091-45a4-9358-71668ecbf7ea" ) ;
159
163
var id = payment . Id ;
160
164
var amount = payment . Amount ;
161
-
165
+
162
166
ServiceMockHelper . MockJsonResponse ( "Fixtures/CreditCard/Refunded.json" ) ;
163
167
164
168
await Assert . ThrowsAsync < ValidationException >
@@ -176,14 +180,14 @@ public void TestPaymentListing()
176
180
Assert . IsType < CreditCard > ( pagination . Items [ 0 ] . Source ) ;
177
181
Assert . IsType < ApplePayMethod > ( pagination . Items [ 1 ] . Source ) ;
178
182
Assert . IsType < StcPayMethod > ( pagination . Items [ 2 ] . Source ) ;
179
-
183
+
180
184
Assert . Equal ( 2 , pagination . CurrentPage ) ;
181
185
Assert . Equal ( 3 , pagination . NextPage ) ;
182
186
Assert . Equal ( 1 , pagination . PreviousPage ) ;
183
187
Assert . Equal ( 3 , pagination . TotalPages ) ;
184
188
Assert . Equal ( 9 , pagination . TotalCount ) ;
185
189
}
186
-
190
+
187
191
internal static PaymentInfo GetValidPaymentInfo ( IPaymentSource source = null )
188
192
{
189
193
return new PaymentInfo
@@ -212,7 +216,7 @@ private static CreditCardSource GetValidCcSource()
212
216
Year = 2021 ,
213
217
} ;
214
218
}
215
-
219
+
216
220
private static ApplePaySource GetValidApplePaySource ( )
217
221
{
218
222
return new ApplePaySource
0 commit comments