Skip to content

Commit

Permalink
Improve PPL Order request
Browse files Browse the repository at this point in the history
Replace application_context with experience_context, because the
application_context is deprecated.

Set user_action to 'PAY_NOW' because we want to immediately capture the
payment and know the amount.
  • Loading branch information
gbirke committed Aug 9, 2023
1 parent 5e52d03 commit 4c9114c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/Services/PayPal/Model/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static function from( array $apiResponse ): self {
*/
private static function getUrlFromLinks( array $links ): string {
foreach ( $links as $link ) {
if ( $link['rel'] === 'approve' ) {
if ( $link['rel'] === 'payer-action' ) {
return $link['href'];
}
}
Expand Down
19 changes: 11 additions & 8 deletions src/Services/PayPal/Model/OrderParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,17 @@ public function toJSON(): string {
],
],
'intent' => 'CAPTURE',
'application_context' =>
[
'brand_name' => 'Wikimedia Deutschland',
'landing_page' => 'LOGIN',
'user_action' => 'CONTINUE',
'return_url' => $this->returnUrl,
'cancel_url' => $this->cancelUrl,
],
'payment_source' => [
'paypal' => [
'experience_context' => [
'brand_name' => 'Wikimedia Deutschland',
'user_action' => 'PAY_NOW',
"shipping_preference" => 'NO_SHIPPING',
'return_url' => $this->returnUrl,
'cancel_url' => $this->cancelUrl,
]
]
]
],
JSON_THROW_ON_ERROR );
}
Expand Down
16 changes: 10 additions & 6 deletions tests/Data/PaypalAPI/create_order_request.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@
}
],
"intent": "CAPTURE",
"application_context": {
"brand_name": "Wikimedia Deutschland",
"landing_page": "LOGIN",
"user_action": "CONTINUE",
"return_url": "https://example.com/returnUrl",
"cancel_url": "https://example.com/cancelUrl"
"payment_source": {
"paypal": {
"experience_context": {
"brand_name": "Wikimedia Deutschland",
"user_action": "PAY_NOW",
"shipping_preference": "NO_SHIPPING",
"return_url": "https:\/\/example.com\/returnUrl",
"cancel_url": "https:\/\/example.com\/cancelUrl"
}
}
}
}
2 changes: 1 addition & 1 deletion tests/Unit/Services/PayPal/GuzzlePaypalAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ private function createCreateOrderResponse(): Response {
{
"href": "https://www.paypal.com/checkoutnow?token=5O190127TN364715T",
"rel": "approve",
"rel": "payer-action",
"method": "GET"
}
]
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Services/PayPal/Model/OrderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function testCreateFromApiResponse(): void {
],
[
"href" => "https://www.paypal.com/checkoutnow?token=5O190127TN364715T",
"rel" => "approve",
"rel" => "payer-action",
"method" => "GET"
]
]
Expand Down

0 comments on commit 4c9114c

Please sign in to comment.