From 5be7877570c2ab7c40784c8415c533d48c3e5e9b Mon Sep 17 00:00:00 2001 From: avelicka Date: Tue, 23 Jan 2018 23:07:56 +0200 Subject: [PATCH] PaypalChecksum request appended with checkoutOptions. --- lib/Paymill/Models/Request/PaypalChecksum.php | 33 ++++++++++ .../Models/Request/PaypalChecksumTest.php | 63 +++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100755 tests/Unit/Paymill/Models/Request/PaypalChecksumTest.php diff --git a/lib/Paymill/Models/Request/PaypalChecksum.php b/lib/Paymill/Models/Request/PaypalChecksum.php index 93b1a2e..352631a 100755 --- a/lib/Paymill/Models/Request/PaypalChecksum.php +++ b/lib/Paymill/Models/Request/PaypalChecksum.php @@ -77,6 +77,13 @@ class PaypalChecksum extends ChecksumBase */ private $reusablePaymentDescription; + /** + * Checkout options + * + * @var array $checkoutOptions + */ + private $checkoutOptions = []; + /** * Get checksum action * @@ -269,6 +276,29 @@ public function setReusablePaymentDescription($reusablePaymentDescription) return $this; } + /** + * Get checkout options + * + * @return array + */ + public function getCheckoutOptions() + { + return $this->checkoutOptions; + } + + /** + * Set checkout options + * + * @param array $checkoutOptions Checkout options + * @return $this + */ + public function setCheckoutOptions(array $checkoutOptions) + { + $this->checkoutOptions = $checkoutOptions; + + return $this; + } + /** * Converts the model into an array to prepare method calls * @param string $method should be used for handling the required parameter @@ -311,6 +341,9 @@ public function parameterize($method) $parameterArray['reusable_payment_description'] = $this->getReusablePaymentDescription(); } + foreach ($this->getCheckoutOptions() as $name => $value) { + $parameterArray['checkout_options[' . $name . ']'] = $value; + } } return $parameterArray; diff --git a/tests/Unit/Paymill/Models/Request/PaypalChecksumTest.php b/tests/Unit/Paymill/Models/Request/PaypalChecksumTest.php new file mode 100755 index 0000000..e0c4d05 --- /dev/null +++ b/tests/Unit/Paymill/Models/Request/PaypalChecksumTest.php @@ -0,0 +1,63 @@ +setAmount(4200) + ->setCurrency('EUR') + ->setDescription('Some description') + ->setCheckoutOptions([ + 'shipping_address_editable' => true + ]) + ->setReturnUrl('http://foo.de/return') + ->setCancelUrl('http://foo.de/cancel'); + $method = 'create'; + $expectedParameters = [ + 'amount' => 4200, + 'currency' => 'EUR', + 'description' => 'Some description', + 'return_url' => 'http://foo.de/return', + 'cancel_url' => 'http://foo.de/cancel', + 'checkout_options[shipping_address_editable]' => true + ]; + $cases[] = [$model, $method, $expectedParameters]; + + return $cases; + } + + /** + * @param PaypalChecksum $model + * @param string $method + * @param array $expectedParameters + * + * @dataProvider dataProviderForTestParameterize + */ + public function testParameterize(PaypalChecksum $model, $method, $expectedParameters) + { + $parameters = $model->parameterize($method); + + $this->assertEquals($expectedParameters, $parameters); + } +}