@@ -90,6 +90,158 @@ public function testBillingRequestsCreateWithIdempotencyConflict()
90
90
$ this ->assertEquals ($ getRequest ->getUri ()->getPath (), '/billing_requests/ID123 ' );
91
91
}
92
92
93
+ public function testBillingRequestsCreateWithInstalmentsWithDates ()
94
+ {
95
+ $ fixture = $ this ->loadJsonFixture ('billing_requests ' )->create_with_instalments_with_dates ;
96
+ $ this ->stub_request ($ fixture );
97
+
98
+ $ service = $ this ->client ->billingRequests ();
99
+ $ response = call_user_func_array (array ($ service , 'createWithInstalmentsWithDates ' ), (array )$ fixture ->url_params );
100
+
101
+ $ body = $ fixture ->body ->billing_requests ;
102
+
103
+ $ this ->assertInstanceOf ('\GoCardlessPro\Resources\BillingRequest ' , $ response );
104
+
105
+ $ this ->assertEquals ($ body ->actions , $ response ->actions );
106
+ $ this ->assertEquals ($ body ->created_at , $ response ->created_at );
107
+ $ this ->assertEquals ($ body ->fallback_enabled , $ response ->fallback_enabled );
108
+ $ this ->assertEquals ($ body ->fallback_occurred , $ response ->fallback_occurred );
109
+ $ this ->assertEquals ($ body ->id , $ response ->id );
110
+ $ this ->assertEquals ($ body ->instalment_schedule_request , $ response ->instalment_schedule_request );
111
+ $ this ->assertEquals ($ body ->links , $ response ->links );
112
+ $ this ->assertEquals ($ body ->mandate_request , $ response ->mandate_request );
113
+ $ this ->assertEquals ($ body ->metadata , $ response ->metadata );
114
+ $ this ->assertEquals ($ body ->payment_request , $ response ->payment_request );
115
+ $ this ->assertEquals ($ body ->purpose_code , $ response ->purpose_code );
116
+ $ this ->assertEquals ($ body ->resources , $ response ->resources );
117
+ $ this ->assertEquals ($ body ->status , $ response ->status );
118
+ $ this ->assertEquals ($ body ->subscription_request , $ response ->subscription_request );
119
+
120
+
121
+ $ expectedPathRegex = $ this ->extract_resource_fixture_path_regex ($ fixture );
122
+ $ dispatchedRequest = $ this ->history [0 ]['request ' ];
123
+ $ this ->assertMatchesRegularExpression ($ expectedPathRegex , $ dispatchedRequest ->getUri ()->getPath ());
124
+ }
125
+
126
+ public function testBillingRequestsCreateWithInstalmentsWithDatesWithIdempotencyConflict ()
127
+ {
128
+ $ fixture = $ this ->loadJsonFixture ('billing_requests ' )->create_with_instalments_with_dates ;
129
+
130
+ $ idempotencyConflictResponseFixture = $ this ->loadFixture ('idempotent_creation_conflict_invalid_state_error ' );
131
+
132
+ // The POST request responds with a 409 to our original POST, due to an idempotency conflict
133
+ $ this ->mock ->append (new \GuzzleHttp \Psr7 \Response (409 , [], $ idempotencyConflictResponseFixture ));
134
+
135
+ // The client makes a second request to fetch the resource that was already
136
+ // created using our idempotency key. It responds with the created resource,
137
+ // which looks just like the response for a successful POST request.
138
+ $ this ->mock ->append (new \GuzzleHttp \Psr7 \Response (200 , [], json_encode ($ fixture ->body )));
139
+
140
+ $ service = $ this ->client ->billingRequests ();
141
+ $ response = call_user_func_array (array ($ service , 'createWithInstalmentsWithDates ' ), (array )$ fixture ->url_params );
142
+ $ body = $ fixture ->body ->billing_requests ;
143
+
144
+ $ this ->assertInstanceOf ('\GoCardlessPro\Resources\BillingRequest ' , $ response );
145
+
146
+ $ this ->assertEquals ($ body ->actions , $ response ->actions );
147
+ $ this ->assertEquals ($ body ->created_at , $ response ->created_at );
148
+ $ this ->assertEquals ($ body ->fallback_enabled , $ response ->fallback_enabled );
149
+ $ this ->assertEquals ($ body ->fallback_occurred , $ response ->fallback_occurred );
150
+ $ this ->assertEquals ($ body ->id , $ response ->id );
151
+ $ this ->assertEquals ($ body ->instalment_schedule_request , $ response ->instalment_schedule_request );
152
+ $ this ->assertEquals ($ body ->links , $ response ->links );
153
+ $ this ->assertEquals ($ body ->mandate_request , $ response ->mandate_request );
154
+ $ this ->assertEquals ($ body ->metadata , $ response ->metadata );
155
+ $ this ->assertEquals ($ body ->payment_request , $ response ->payment_request );
156
+ $ this ->assertEquals ($ body ->purpose_code , $ response ->purpose_code );
157
+ $ this ->assertEquals ($ body ->resources , $ response ->resources );
158
+ $ this ->assertEquals ($ body ->status , $ response ->status );
159
+ $ this ->assertEquals ($ body ->subscription_request , $ response ->subscription_request );
160
+
161
+
162
+ $ expectedPathRegex = $ this ->extract_resource_fixture_path_regex ($ fixture );
163
+ $ conflictRequest = $ this ->history [0 ]['request ' ];
164
+ $ this ->assertMatchesRegularExpression ($ expectedPathRegex , $ conflictRequest ->getUri ()->getPath ());
165
+ $ getRequest = $ this ->history [1 ]['request ' ];
166
+ $ this ->assertEquals ($ getRequest ->getUri ()->getPath (), '/billing_requests/ID123 ' );
167
+ }
168
+
169
+ public function testBillingRequestsCreateWithInstalmentsWithSchedule ()
170
+ {
171
+ $ fixture = $ this ->loadJsonFixture ('billing_requests ' )->create_with_instalments_with_schedule ;
172
+ $ this ->stub_request ($ fixture );
173
+
174
+ $ service = $ this ->client ->billingRequests ();
175
+ $ response = call_user_func_array (array ($ service , 'createWithInstalmentsWithSchedule ' ), (array )$ fixture ->url_params );
176
+
177
+ $ body = $ fixture ->body ->billing_requests ;
178
+
179
+ $ this ->assertInstanceOf ('\GoCardlessPro\Resources\BillingRequest ' , $ response );
180
+
181
+ $ this ->assertEquals ($ body ->actions , $ response ->actions );
182
+ $ this ->assertEquals ($ body ->created_at , $ response ->created_at );
183
+ $ this ->assertEquals ($ body ->fallback_enabled , $ response ->fallback_enabled );
184
+ $ this ->assertEquals ($ body ->fallback_occurred , $ response ->fallback_occurred );
185
+ $ this ->assertEquals ($ body ->id , $ response ->id );
186
+ $ this ->assertEquals ($ body ->instalment_schedule_request , $ response ->instalment_schedule_request );
187
+ $ this ->assertEquals ($ body ->links , $ response ->links );
188
+ $ this ->assertEquals ($ body ->mandate_request , $ response ->mandate_request );
189
+ $ this ->assertEquals ($ body ->metadata , $ response ->metadata );
190
+ $ this ->assertEquals ($ body ->payment_request , $ response ->payment_request );
191
+ $ this ->assertEquals ($ body ->purpose_code , $ response ->purpose_code );
192
+ $ this ->assertEquals ($ body ->resources , $ response ->resources );
193
+ $ this ->assertEquals ($ body ->status , $ response ->status );
194
+ $ this ->assertEquals ($ body ->subscription_request , $ response ->subscription_request );
195
+
196
+
197
+ $ expectedPathRegex = $ this ->extract_resource_fixture_path_regex ($ fixture );
198
+ $ dispatchedRequest = $ this ->history [0 ]['request ' ];
199
+ $ this ->assertMatchesRegularExpression ($ expectedPathRegex , $ dispatchedRequest ->getUri ()->getPath ());
200
+ }
201
+
202
+ public function testBillingRequestsCreateWithInstalmentsWithScheduleWithIdempotencyConflict ()
203
+ {
204
+ $ fixture = $ this ->loadJsonFixture ('billing_requests ' )->create_with_instalments_with_schedule ;
205
+
206
+ $ idempotencyConflictResponseFixture = $ this ->loadFixture ('idempotent_creation_conflict_invalid_state_error ' );
207
+
208
+ // The POST request responds with a 409 to our original POST, due to an idempotency conflict
209
+ $ this ->mock ->append (new \GuzzleHttp \Psr7 \Response (409 , [], $ idempotencyConflictResponseFixture ));
210
+
211
+ // The client makes a second request to fetch the resource that was already
212
+ // created using our idempotency key. It responds with the created resource,
213
+ // which looks just like the response for a successful POST request.
214
+ $ this ->mock ->append (new \GuzzleHttp \Psr7 \Response (200 , [], json_encode ($ fixture ->body )));
215
+
216
+ $ service = $ this ->client ->billingRequests ();
217
+ $ response = call_user_func_array (array ($ service , 'createWithInstalmentsWithSchedule ' ), (array )$ fixture ->url_params );
218
+ $ body = $ fixture ->body ->billing_requests ;
219
+
220
+ $ this ->assertInstanceOf ('\GoCardlessPro\Resources\BillingRequest ' , $ response );
221
+
222
+ $ this ->assertEquals ($ body ->actions , $ response ->actions );
223
+ $ this ->assertEquals ($ body ->created_at , $ response ->created_at );
224
+ $ this ->assertEquals ($ body ->fallback_enabled , $ response ->fallback_enabled );
225
+ $ this ->assertEquals ($ body ->fallback_occurred , $ response ->fallback_occurred );
226
+ $ this ->assertEquals ($ body ->id , $ response ->id );
227
+ $ this ->assertEquals ($ body ->instalment_schedule_request , $ response ->instalment_schedule_request );
228
+ $ this ->assertEquals ($ body ->links , $ response ->links );
229
+ $ this ->assertEquals ($ body ->mandate_request , $ response ->mandate_request );
230
+ $ this ->assertEquals ($ body ->metadata , $ response ->metadata );
231
+ $ this ->assertEquals ($ body ->payment_request , $ response ->payment_request );
232
+ $ this ->assertEquals ($ body ->purpose_code , $ response ->purpose_code );
233
+ $ this ->assertEquals ($ body ->resources , $ response ->resources );
234
+ $ this ->assertEquals ($ body ->status , $ response ->status );
235
+ $ this ->assertEquals ($ body ->subscription_request , $ response ->subscription_request );
236
+
237
+
238
+ $ expectedPathRegex = $ this ->extract_resource_fixture_path_regex ($ fixture );
239
+ $ conflictRequest = $ this ->history [0 ]['request ' ];
240
+ $ this ->assertMatchesRegularExpression ($ expectedPathRegex , $ conflictRequest ->getUri ()->getPath ());
241
+ $ getRequest = $ this ->history [1 ]['request ' ];
242
+ $ this ->assertEquals ($ getRequest ->getUri ()->getPath (), '/billing_requests/ID123 ' );
243
+ }
244
+
93
245
public function testBillingRequestsCollectCustomerDetails ()
94
246
{
95
247
$ fixture = $ this ->loadJsonFixture ('billing_requests ' )->collect_customer_details ;
0 commit comments