1313
1414namespace spec \Sylius \PayPalPlugin \Api ;
1515
16- use GuzzleHttp \Client ;
1716use Payum \Core \Model \GatewayConfigInterface ;
1817use PhpSpec \ObjectBehavior ;
1918use Prophecy \Argument ;
20- use Psr \Http \Message \ResponseInterface ;
21- use Psr \Http \Message \StreamInterface ;
2219use Sylius \Component \Core \Model \AddressInterface ;
2320use Sylius \Component \Core \Model \OrderInterface ;
2421use Sylius \Component \Core \Model \PaymentInterface ;
2522use Sylius \Component \Core \Model \PaymentMethodInterface ;
2623use Sylius \PayPalPlugin \Api \CreateOrderApiInterface ;
24+ use Sylius \PayPalPlugin \Client \PayPalClientInterface ;
2725
2826final class CreateOrderApiSpec extends ObjectBehavior
2927{
30- function let (Client $ client ): void
28+ function let (PayPalClientInterface $ client ): void
3129 {
32- $ this ->beConstructedWith ($ client, ' https://api.test-paypal.com/ ' , ' PARTNER_ATTRIBUTION_ID ' );
30+ $ this ->beConstructedWith ($ client );
3331 }
3432
3533 function it_implements_create_order_api_interface (): void
@@ -38,11 +36,9 @@ function it_implements_create_order_api_interface(): void
3836 }
3937
4038 function it_creates_pay_pal_order_based_on_given_payment (
41- Client $ client ,
39+ PayPalClientInterface $ client ,
4240 PaymentInterface $ payment ,
4341 OrderInterface $ order ,
44- ResponseInterface $ response ,
45- StreamInterface $ body ,
4642 PaymentMethodInterface $ paymentMethod ,
4743 GatewayConfigInterface $ gatewayConfig
4844 ): void {
@@ -58,30 +54,25 @@ function it_creates_pay_pal_order_based_on_given_payment(
5854 ['merchant_id ' => 'merchant-id ' , 'sylius_merchant_id ' => 'sylius-merchant-id ' ]
5955 );
6056
61- $ client ->request (
62- 'POST ' ,
63- 'https://api.test-paypal.com/v2/checkout/orders ' ,
57+ $ client ->post (
58+ 'v2/checkout/orders ' ,
59+ 'TOKEN ' ,
6460 Argument::that (function (array $ data ): bool {
6561 return
66- $ data ['headers ' ]['Authorization ' ] === 'Bearer TOKEN ' &&
67- $ data ['json ' ]['intent ' ] === 'CAPTURE ' &&
68- $ data ['json ' ]['purchase_units ' ][0 ]['amount ' ]['value ' ] === 100 &&
69- $ data ['json ' ]['purchase_units ' ][0 ]['amount ' ]['currency_code ' ] === 'PLN '
62+ $ data ['intent ' ] === 'CAPTURE ' &&
63+ $ data ['purchase_units ' ][0 ]['amount ' ]['value ' ] === 100 &&
64+ $ data ['purchase_units ' ][0 ]['amount ' ]['currency_code ' ] === 'PLN '
7065 ;
7166 })
72- )->willReturn ($ response );
73- $ response ->getBody ()->willReturn ($ body );
74- $ body ->getContents ()->willReturn ('{"status": "CREATED", "id": 123} ' );
67+ )->willReturn (['status ' => 'CREATED ' , 'id ' => 123 ]);
7568
7669 $ this ->create ('TOKEN ' , $ payment )->shouldReturn (['status ' => 'CREATED ' , 'id ' => 123 ]);
7770 }
7871
7972 function it_creates_pay_pal_order_with_shipping_address_based_on_given_payment (
80- Client $ client ,
73+ PayPalClientInterface $ client ,
8174 PaymentInterface $ payment ,
8275 OrderInterface $ order ,
83- ResponseInterface $ response ,
84- StreamInterface $ body ,
8576 PaymentMethodInterface $ paymentMethod ,
8677 GatewayConfigInterface $ gatewayConfig ,
8778 AddressInterface $ shippingAddress
@@ -104,25 +95,22 @@ function it_creates_pay_pal_order_with_shipping_address_based_on_given_payment(
10495 ['merchant_id ' => 'merchant-id ' , 'sylius_merchant_id ' => 'sylius-merchant-id ' ]
10596 );
10697
107- $ client ->request (
108- 'POST ' ,
109- 'https://api.test-paypal.com/v2/checkout/orders ' ,
98+ $ client ->post (
99+ 'v2/checkout/orders ' ,
100+ 'TOKEN ' ,
110101 Argument::that (function (array $ data ): bool {
111102 return
112- $ data ['headers ' ]['Authorization ' ] === 'Bearer TOKEN ' &&
113- $ data ['json ' ]['intent ' ] === 'CAPTURE ' &&
114- $ data ['json ' ]['purchase_units ' ][0 ]['amount ' ]['value ' ] === 100 &&
115- $ data ['json ' ]['purchase_units ' ][0 ]['amount ' ]['currency_code ' ] === 'PLN ' &&
116- $ data ['json ' ]['purchase_units ' ][0 ]['shipping ' ]['name ' ]['full_name ' ] === 'Gandalf The Grey ' &&
117- $ data ['json ' ]['purchase_units ' ][0 ]['shipping ' ]['address ' ]['address_line_1 ' ] === 'Hobbit St. 123 ' &&
118- $ data ['json ' ]['purchase_units ' ][0 ]['shipping ' ]['address ' ]['admin_area_2 ' ] === 'Minas Tirith ' &&
119- $ data ['json ' ]['purchase_units ' ][0 ]['shipping ' ]['address ' ]['postal_code ' ] === '000 ' &&
120- $ data ['json ' ]['purchase_units ' ][0 ]['shipping ' ]['address ' ]['country_code ' ] === 'US '
103+ $ data ['intent ' ] === 'CAPTURE ' &&
104+ $ data ['purchase_units ' ][0 ]['amount ' ]['value ' ] === 100 &&
105+ $ data ['purchase_units ' ][0 ]['amount ' ]['currency_code ' ] === 'PLN ' &&
106+ $ data ['purchase_units ' ][0 ]['shipping ' ]['name ' ]['full_name ' ] === 'Gandalf The Grey ' &&
107+ $ data ['purchase_units ' ][0 ]['shipping ' ]['address ' ]['address_line_1 ' ] === 'Hobbit St. 123 ' &&
108+ $ data ['purchase_units ' ][0 ]['shipping ' ]['address ' ]['admin_area_2 ' ] === 'Minas Tirith ' &&
109+ $ data ['purchase_units ' ][0 ]['shipping ' ]['address ' ]['postal_code ' ] === '000 ' &&
110+ $ data ['purchase_units ' ][0 ]['shipping ' ]['address ' ]['country_code ' ] === 'US '
121111 ;
122112 })
123- )->willReturn ($ response );
124- $ response ->getBody ()->willReturn ($ body );
125- $ body ->getContents ()->willReturn ('{"status": "CREATED", "id": 123} ' );
113+ )->willReturn (['status ' => 'CREATED ' , 'id ' => 123 ]);
126114
127115 $ this ->create ('TOKEN ' , $ payment )->shouldReturn (['status ' => 'CREATED ' , 'id ' => 123 ]);
128116 }
0 commit comments