Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PaypalChecksum request appended with checkoutOptions. #145

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions lib/Paymill/Models/Request/PaypalChecksum.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ class PaypalChecksum extends ChecksumBase
*/
private $reusablePaymentDescription;

/**
* Checkout options
*
* @var array $checkoutOptions
*/
private $checkoutOptions = [];

/**
* Get checksum action
*
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
63 changes: 63 additions & 0 deletions tests/Unit/Paymill/Models/Request/PaypalChecksumTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace Paymill\Tests\Unit\Models\Request;

use Paymill\Models\Request\PaypalChecksum;
use PHPUnit_Framework_TestCase;

/**
* Paymill\Models\Request\PaypalChecksum test case.
*/
class PaypalChecksumTest extends PHPUnit_Framework_TestCase
{
/**
* @return array
*/
public function dataProviderForTestParameterize()
{
$cases = [];

// Case 0
$model = new PaypalChecksum();
$method = 'create';
$expectedParameters = [];
$cases[] = [$model, $method, $expectedParameters];

// Case 1
$model = (new PaypalChecksum())
->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);
}
}