Skip to content
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
15 changes: 15 additions & 0 deletions lib/Checkout/Payments/Hosted/HostedPaymentsSessionRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,19 @@
* @var array values of AmountAllocations
*/
public $amount_allocations;

/**
* The authorization type.
* [Optional]
* Allowed values: "Final", "Estimated". Defaults to "Final".
* @var string|null $authorization_type
*/
public $authorization_type;

Check warning on line 184 in lib/Checkout/Payments/Hosted/HostedPaymentsSessionRequest.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this field "$authorization_type" to match the regular expression ^[a-z][a-zA-Z0-9]*$.

See more on https://sonarcloud.io/project/issues?id=checkout_checkout-sdk-php&issues=AZ7fO_uAyrinr0FAiuhl&open=AZ7fO_uAyrinr0FAiuhl&pullRequest=341

/**
* The payment plan details. To be used when the payment_type is Recurring.
* [Optional]
* @var \Checkout\Payments\PaymentPlan|null $payment_plan
*/
public $payment_plan;

Check warning on line 191 in lib/Checkout/Payments/Hosted/HostedPaymentsSessionRequest.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this field "$payment_plan" to match the regular expression ^[a-z][a-zA-Z0-9]*$.

See more on https://sonarcloud.io/project/issues?id=checkout_checkout-sdk-php&issues=AZ7fO_uAyrinr0FAiuhm&open=AZ7fO_uAyrinr0FAiuhm&pullRequest=341
}
15 changes: 15 additions & 0 deletions lib/Checkout/Payments/Links/PaymentLinkRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,19 @@
* @var array values of AmountAllocations
*/
public $amount_allocations;

/**
* The authorization type.
* [Optional]
* Allowed values: "Final", "Estimated". Defaults to "Final".
* @var string|null $authorization_type
*/
public $authorization_type;

Check warning on line 192 in lib/Checkout/Payments/Links/PaymentLinkRequest.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this field "$authorization_type" to match the regular expression ^[a-z][a-zA-Z0-9]*$.

See more on https://sonarcloud.io/project/issues?id=checkout_checkout-sdk-php&issues=AZ7fO_u8yrinr0FAiuho&open=AZ7fO_u8yrinr0FAiuho&pullRequest=341

/**
* The payment plan details. To be used when the payment_type is Recurring.
* [Optional]
* @var \Checkout\Payments\PaymentPlan|null $payment_plan
*/
public $payment_plan;

Check warning on line 199 in lib/Checkout/Payments/Links/PaymentLinkRequest.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this field "$payment_plan" to match the regular expression ^[a-z][a-zA-Z0-9]*$.

See more on https://sonarcloud.io/project/issues?id=checkout_checkout-sdk-php&issues=AZ7fO_u8yrinr0FAiuhp&open=AZ7fO_u8yrinr0FAiuhp&pullRequest=341
}
8 changes: 8 additions & 0 deletions lib/Checkout/Payments/PaymentPlan.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@

class PaymentPlan
{
/**
* Specifies whether the amount is fixed or variable for each recurrence.
* [Optional]
* Allowed values: "Fixed", "Variable".
* @var string|null $amount_variability
*/
public $amount_variability;

Check warning on line 13 in lib/Checkout/Payments/PaymentPlan.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this field "$amount_variability" to match the regular expression ^[a-z][a-zA-Z0-9]*$.

See more on https://sonarcloud.io/project/issues?id=checkout_checkout-sdk-php&issues=AZ7fO_uXyrinr0FAiuhn&open=AZ7fO_uXyrinr0FAiuhn&pullRequest=341

/**
* Indicates the minimum number of days between payments.
* [Optional]
Expand Down
15 changes: 15 additions & 0 deletions lib/Checkout/Payments/Sessions/PaymentSessionsRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,19 @@
* @var string
*/
public $ip_address;

/**
* The authorization type.
* [Optional]
* Allowed values: "Final", "Estimated". Defaults to "Final".
* @var string|null $authorization_type
*/
public $authorization_type;

Check warning on line 185 in lib/Checkout/Payments/Sessions/PaymentSessionsRequest.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this field "$authorization_type" to match the regular expression ^[a-z][a-zA-Z0-9]*$.

See more on https://sonarcloud.io/project/issues?id=checkout_checkout-sdk-php&issues=AZ7fO_q9yrinr0FAiuhj&open=AZ7fO_q9yrinr0FAiuhj&pullRequest=341

/**
* The payment plan details. To be used when the payment_type is Recurring.
* [Optional]
* @var \Checkout\Payments\PaymentPlan|null $payment_plan
*/
public $payment_plan;

Check warning on line 192 in lib/Checkout/Payments/Sessions/PaymentSessionsRequest.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this field "$payment_plan" to match the regular expression ^[a-z][a-zA-Z0-9]*$.

See more on https://sonarcloud.io/project/issues?id=checkout_checkout-sdk-php&issues=AZ7fO_q9yrinr0FAiuhk&open=AZ7fO_q9yrinr0FAiuhk&pullRequest=341
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace Checkout\Tests\Payments;

use Checkout\JsonSerializer;
use Checkout\Payments\Hosted\HostedPaymentsSessionRequest;
use Checkout\Payments\Links\PaymentLinkRequest;
use Checkout\Payments\PaymentPlan;
use Checkout\Payments\Sessions\PaymentSessionsRequest;
use PHPUnit\Framework\TestCase;

class PaymentRequestFieldsSerializationTest extends TestCase
{
private function paymentPlan()
{
$plan = new PaymentPlan();
$plan->amount_variability = 'Variable';
$plan->days_between_payments = 28;
$plan->total_number_of_payments = 5;
$plan->current_payment_number = 3;
return $plan;
}

public function testHostedPaymentsSessionRequestSerializesAuthorizationTypeAndPaymentPlan()
{
$request = new HostedPaymentsSessionRequest();
$request->authorization_type = "Estimated";
$request->payment_plan = $this->paymentPlan();

$decoded = json_decode((new JsonSerializer())->serialize($request), true);

$this->assertSame("Estimated", $decoded['authorization_type']);
$this->assertSame('Variable', $decoded['payment_plan']['amount_variability']);
$this->assertSame(28, $decoded['payment_plan']['days_between_payments']);
$this->assertSame(5, $decoded['payment_plan']['total_number_of_payments']);
}

public function testPaymentLinkRequestSerializesAuthorizationTypeAndPaymentPlan()
{
$request = new PaymentLinkRequest();
$request->authorization_type = "Final";
$request->payment_plan = $this->paymentPlan();

$decoded = json_decode((new JsonSerializer())->serialize($request), true);

$this->assertSame("Final", $decoded['authorization_type']);
$this->assertSame('Variable', $decoded['payment_plan']['amount_variability']);
$this->assertSame(28, $decoded['payment_plan']['days_between_payments']);
}

public function testPaymentSessionsRequestSerializesAuthorizationTypeAndPaymentPlan()
{
$request = new PaymentSessionsRequest();
$request->authorization_type = "Estimated";
$request->payment_plan = $this->paymentPlan();

$decoded = json_decode((new JsonSerializer())->serialize($request), true);

$this->assertSame("Estimated", $decoded['authorization_type']);
$this->assertSame('Variable', $decoded['payment_plan']['amount_variability']);
$this->assertSame(3, $decoded['payment_plan']['current_payment_number']);
}

public function testUnsetFieldsAreOmittedFromSerialization()
{
$request = new PaymentSessionsRequest();
$decoded = json_decode((new JsonSerializer())->serialize($request), true);

$this->assertArrayNotHasKey('authorization_type', $decoded);
$this->assertArrayNotHasKey('payment_plan', $decoded);
}
}
Loading