33namespace Pagarme \Core \Test \Recurrence \Aggregates ;
44
55use Mockery ;
6+ use MundiAPILib \Models \CreateAddressRequest ;
7+ use MundiAPILib \Models \CreateCardRequest ;
68use MundiAPILib \Models \CreateSubscriptionRequest ;
79use Pagarme \Core \Kernel \Interfaces \PlatformOrderInterface ;
810use Pagarme \Core \Kernel \ValueObjects \Id \ChargeId ;
@@ -187,4 +189,52 @@ public function testShouldSetAnArrayOfChargesOnSubscription()
187189 $ this ->assertContainsOnlyInstancesOf (Charge::class, $ this ->subscription ->getCharges ());
188190 $ this ->assertCount (2 , $ this ->subscription ->getCharges ());
189191 }
190- }
192+
193+ public function testShouldReturnACreateSubscriptionRequestObjectWithCardBillingAddress ()
194+ {
195+ $ this ->subscription ->setCustomer (new Customer ());
196+ $ this ->subscription ->setItems ([new SubProduct ]);
197+ $ this ->subscription ->getCustomer ()->setAddress (new Address ());
198+ $ this ->subscription ->setCardToken ("cardToken " );
199+
200+ $ shipping = new Shipping ;
201+ $ shipping ->setRecipientPhone (new Phone ("021999999999 " ));
202+ $ shipping ->setAddress (new Address ());
203+
204+ $ this ->subscription ->setShipping ($ shipping );
205+
206+ $ card = new CreateCardRequest ();
207+ $ card ->billingAddress = $ this ->subscription ->getCustomer ()
208+ ->getAddress ()->convertToSDKRequest ();
209+ $ this ->subscription ->card = $ card ;
210+
211+ $ sdkObject = $ this ->subscription ->convertToSdkRequest ();
212+
213+ $ this ->assertInstanceOf (CreateSubscriptionRequest::class, $ sdkObject );
214+ $ this ->assertNotNull ($ sdkObject ->card ->billingAddress );
215+ }
216+
217+ public function testShouldReturnACreateSubscriptionRequestObjectWithSavedCardBillingAddress ()
218+ {
219+ $ this ->subscription ->setCustomer (new Customer ());
220+ $ this ->subscription ->setItems ([new SubProduct ]);
221+ $ this ->subscription ->getCustomer ()->setAddress (new Address ());
222+ $ this ->subscription ->setCardId ("cardId " );
223+
224+ $ shipping = new Shipping ;
225+ $ shipping ->setRecipientPhone (new Phone ("021999999999 " ));
226+ $ shipping ->setAddress (new Address ());
227+
228+ $ this ->subscription ->setShipping ($ shipping );
229+
230+ $ card = new CreateCardRequest ();
231+ $ card ->billingAddress = $ this ->subscription ->getCustomer ()
232+ ->getAddress ()->convertToSDKRequest ();
233+ $ this ->subscription ->card = $ card ;
234+
235+ $ sdkObject = $ this ->subscription ->convertToSdkRequest ();
236+
237+ $ this ->assertInstanceOf (CreateSubscriptionRequest::class, $ sdkObject );
238+ $ this ->assertNotNull ($ sdkObject ->card ->billingAddress );
239+ }
240+ }
0 commit comments