-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create Payer Payload only from required and existing data (#142)
- Loading branch information
Showing
2 changed files
with
166 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,14 +31,74 @@ protected function setUp(): void | |
{ | ||
$this->callbackUrlGenerator = $this->prophesize(CallbackUrlGeneratorInterface::class); | ||
$this->translator = $this->prophesize(TranslatorInterface::class); | ||
} | ||
|
||
public function test_it_returns_a_payload_for_a_redirect_based_payment(): void | ||
{ | ||
$billingAddress = $this->prophesize(AddressInterface::class); | ||
$billingAddress->getFullName()->willReturn('Don Matteo'); | ||
|
||
$customer = $this->prophesize(CustomerInterface::class); | ||
$customer->getEmail()->willReturn('[email protected]'); | ||
|
||
$order = $this->prophesize(OrderInterface::class); | ||
$order->getCustomer()->willReturn($customer); | ||
$order->getBillingAddress()->willReturn($billingAddress); | ||
$order->getNumber()->willReturn('000000001'); | ||
|
||
$payment = $this->prophesize(PaymentInterface::class); | ||
$payment->getDetails()->willReturn([]); | ||
$payment->getOrder()->willReturn($order); | ||
$payment->getAmount()->willReturn(1050); | ||
|
||
$billingAddress->getPhoneNumber()->willReturn('123123123'); | ||
$billingAddress->getStreet()->willReturn('Sesame Street'); | ||
$billingAddress->getCity()->willReturn('Sesame City'); | ||
$billingAddress->getPostcode()->willReturn('90 210'); | ||
$billingAddress->getCountryCode()->willReturn('PL'); | ||
|
||
$this->translator->trans( | ||
'commerce_weavers_sylius_tpay.tpay.transaction_description', | ||
['%orderNumber%' => '000000001'] | ||
)->willReturn(self::TRANSLATED_DESCRIPTION); | ||
|
||
$this->callbackUrlGenerator | ||
->generateSuccessUrl($payment, 'pl_PL') | ||
->willReturn('https://cw.org/success') | ||
; | ||
$this->callbackUrlGenerator | ||
->generateFailureUrl($payment, 'pl_PL') | ||
->willReturn('https://cw.org/error') | ||
; | ||
|
||
$payload = $this->createTestSubject()->createFrom($payment->reveal(), 'https://cw.org/notify', 'pl_PL'); | ||
|
||
$this->assertSame([ | ||
'amount' => '10.50', | ||
'description' => self::TRANSLATED_DESCRIPTION, | ||
'lang' => 'pl', | ||
'payer' => [ | ||
'email' => '[email protected]', | ||
'name' => 'Don Matteo', | ||
'phone' => '123123123', | ||
'address' => 'Sesame Street', | ||
'city' => 'Sesame City', | ||
'code' => '90 210', | ||
'country' => 'PL', | ||
], | ||
'callbacks' => [ | ||
'payerUrls' => [ | ||
'success' => 'https://cw.org/success', | ||
'error' => 'https://cw.org/error', | ||
], | ||
'notification' => [ | ||
'url' => 'https://cw.org/notify', | ||
], | ||
], | ||
], $payload); | ||
} | ||
|
||
public function test_it_returns_a_payload_for_a_redirect_based_payment(): void | ||
public function test_it_returns_a_payload_with_fields_that_have_value_only(): void | ||
{ | ||
$billingAddress = $this->prophesize(AddressInterface::class); | ||
$billingAddress->getFullName()->willReturn('Don Matteo'); | ||
|
@@ -57,11 +117,16 @@ public function test_it_returns_a_payload_for_a_redirect_based_payment(): void | |
$payment->getAmount()->willReturn(1050); | ||
|
||
$billingAddress->getPhoneNumber()->willReturn('123123123'); | ||
$billingAddress->getStreet()->willReturn('Sesame Street'); | ||
$billingAddress->getCity()->willReturn('Sesame City'); | ||
$billingAddress->getStreet()->willReturn(''); | ||
$billingAddress->getCity()->willReturn(''); | ||
$billingAddress->getPostcode()->willReturn('90 210'); | ||
$billingAddress->getCountryCode()->willReturn('PL'); | ||
|
||
$this->translator->trans( | ||
'commerce_weavers_sylius_tpay.tpay.transaction_description', | ||
['%orderNumber%' => '000000001'] | ||
)->willReturn(self::TRANSLATED_DESCRIPTION); | ||
|
||
$this->callbackUrlGenerator | ||
->generateSuccessUrl($payment, 'pl_PL') | ||
->willReturn('https://cw.org/success') | ||
|
@@ -81,6 +146,69 @@ public function test_it_returns_a_payload_for_a_redirect_based_payment(): void | |
'email' => '[email protected]', | ||
'name' => 'Don Matteo', | ||
'phone' => '123123123', | ||
'code' => '90 210', | ||
'country' => 'PL', | ||
], | ||
'callbacks' => [ | ||
'payerUrls' => [ | ||
'success' => 'https://cw.org/success', | ||
'error' => 'https://cw.org/error', | ||
], | ||
'notification' => [ | ||
'url' => 'https://cw.org/notify', | ||
], | ||
], | ||
], $payload); | ||
} | ||
|
||
public function test_it_always_returns_a_payload_with_required_fields_even_if_their_value_is_empty(): void | ||
{ | ||
$billingAddress = $this->prophesize(AddressInterface::class); | ||
$billingAddress->getFullName()->willReturn(''); | ||
|
||
$customer = $this->prophesize(CustomerInterface::class); | ||
$customer->getEmail()->willReturn(''); | ||
|
||
$order = $this->prophesize(OrderInterface::class); | ||
$order->getCustomer()->willReturn($customer); | ||
$order->getBillingAddress()->willReturn($billingAddress); | ||
$order->getNumber()->willReturn('000000001'); | ||
|
||
$payment = $this->prophesize(PaymentInterface::class); | ||
$payment->getDetails()->willReturn([]); | ||
$payment->getOrder()->willReturn($order); | ||
$payment->getAmount()->willReturn(1050); | ||
|
||
$billingAddress->getPhoneNumber()->willReturn('123123123'); | ||
$billingAddress->getStreet()->willReturn('Sesame Street'); | ||
$billingAddress->getCity()->willReturn('Sesame City'); | ||
$billingAddress->getPostcode()->willReturn('90 210'); | ||
$billingAddress->getCountryCode()->willReturn('PL'); | ||
|
||
$this->translator->trans( | ||
'commerce_weavers_sylius_tpay.tpay.transaction_description', | ||
['%orderNumber%' => '000000001'] | ||
)->willReturn(self::TRANSLATED_DESCRIPTION); | ||
|
||
$this->callbackUrlGenerator | ||
->generateSuccessUrl($payment, 'pl_PL') | ||
->willReturn('https://cw.org/success') | ||
; | ||
$this->callbackUrlGenerator | ||
->generateFailureUrl($payment, 'pl_PL') | ||
->willReturn('https://cw.org/error') | ||
; | ||
|
||
$payload = $this->createTestSubject()->createFrom($payment->reveal(), 'https://cw.org/notify', 'pl_PL'); | ||
|
||
$this->assertSame([ | ||
'amount' => '10.50', | ||
'description' => self::TRANSLATED_DESCRIPTION, | ||
'lang' => 'pl', | ||
'payer' => [ | ||
'email' => '', | ||
'name' => '', | ||
'phone' => '123123123', | ||
'address' => 'Sesame Street', | ||
'city' => 'Sesame City', | ||
'code' => '90 210', | ||
|
@@ -103,6 +231,8 @@ public function test_it_throws_an_exception_if_the_order_is_null(): void | |
$this->expectException(InvalidArgumentException::class); | ||
|
||
$payment = $this->prophesize(PaymentInterface::class); | ||
$payment->getAmount()->willReturn(1050); | ||
$payment->getOrder()->willReturn(null); | ||
|
||
$this->createTestSubject()->createFrom($payment->reveal(), 'https://cw.org/notify', 'pl_PL'); | ||
} | ||
|
@@ -116,7 +246,8 @@ public function test_it_throws_an_exception_if_the_customer_is_null(): void | |
$order->getCustomer()->willReturn(null); | ||
|
||
$payment = $this->prophesize(PaymentInterface::class); | ||
$payment->getOrder()->willReturn($order); | ||
$payment->getAmount()->willReturn(1050); | ||
$payment->getOrder()->willReturn(null); | ||
|
||
$this->createTestSubject()->createFrom($payment->reveal(), 'https://cw.org/notify', 'pl_PL'); | ||
} | ||
|
@@ -129,9 +260,11 @@ public function test_it_throws_an_exception_if_the_billing_address_is_null(): vo | |
|
||
$order = $this->prophesize(OrderInterface::class); | ||
$order->getCustomer()->willReturn($customer); | ||
$order->getNumber()->willReturn('000000001'); | ||
$order->getBillingAddress()->willReturn(null); | ||
|
||
$payment = $this->prophesize(PaymentInterface::class); | ||
$payment->getAmount()->willReturn(1050); | ||
$payment->getOrder()->willReturn($order); | ||
|
||
$this->createTestSubject()->createFrom($payment->reveal(), 'https://cw.org/notify', 'pl_PL'); | ||
|