Skip to content

Epic: Update PayPal gateway to use card fields API #7853

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

Merged
merged 2 commits into from
Apr 14, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*
* This class use as request to create a webhook.
*
* @unreleased Add PayPal-Partner-Attribution-Id header
* @since 2.32.0
*/
class CreateWebhook extends HttpRequest
Expand All @@ -18,6 +19,7 @@ public function __construct(array $requestBody)
parent::__construct('/v1/notifications/webhooks', 'POST');

$this->headers["Content-Type"] = "application/json";
$this->headers["PayPal-Partner-Attribution-Id"] = give('PAYPAL_COMMERCE_ATTRIBUTION_ID');
$this->body = wp_json_encode($requestBody);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
class DeleteWebhook extends HttpRequest
{
/**
* @unreleased Add PayPal-Partner-Attribution-Id header
* @since 2.32.0
*
* @param string $webhookId Webhook ID.
Expand All @@ -16,5 +17,6 @@ public function __construct(string $webhookId)
parent::__construct("/v1/notifications/webhooks/$webhookId", 'DELETE');

$this->headers['Content-Type'] = 'application/json';
$this->headers["PayPal-Partner-Attribution-Id"] = give('PAYPAL_COMMERCE_ATTRIBUTION_ID');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*
* This class use to generate a client token for PayPal JS SDK.
*
* @unreleased Add PayPal-Partner-Attribution-Id header
* @since 2.30.0
*/
class GenerateClientToken extends HttpRequest
Expand All @@ -19,5 +20,6 @@ class GenerateClientToken extends HttpRequest
public function __construct()
{
parent::__construct('/v1/identity/generate-token', 'POST');
$this->headers["PayPal-Partner-Attribution-Id"] = give('PAYPAL_COMMERCE_ATTRIBUTION_ID');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/**
* Class GetAccessTokenWithClientCredentials
*
* @unreleased Add PayPal-Partner-Attribution-Id header
* @since 2.32.0
*/
class GetAccessToken extends HttpRequest
Expand All @@ -24,6 +25,7 @@ public function __construct(array $requestBody, array $headers)
$this->headers = wp_parse_args($headers, $this->headers);

$this->headers["Content-Type"] = "application/x-www-form-urlencoded";
$this->headers["PayPal-Partner-Attribution-Id"] = give('PAYPAL_COMMERCE_ATTRIBUTION_ID');
$this->body = $requestBody;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/**
* Class UpdateWebhook.
*
* @unreleased Add PayPal-Partner-Attribution-Id header
* @since 2.32.0
*/
class UpdateWebhook extends HttpRequest
Expand All @@ -22,6 +23,7 @@ public function __construct(string $webhookId, array $requestBody)
parent::__construct("/v1/notifications/webhooks/$webhookId", 'PATCH');

$this->headers['Content-Type'] = 'application/json';
$this->headers["PayPal-Partner-Attribution-Id"] = give('PAYPAL_COMMERCE_ATTRIBUTION_ID');
$this->body = wp_json_encode($requestBody);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
/**
* Class VerifyWebhookSignature
*
* @unreleased Add PayPal-Partner-Attribution-Id header
* @since 2.30.0
*/
class VerifyWebhookSignature extends HttpRequest
Expand All @@ -19,6 +20,7 @@ public function __construct(array $requestBody)
parent::__construct('/v1/notifications/verify-webhook-signature', 'POST');

$this->headers["Content-Type"] = "application/json";
$this->headers["PayPal-Partner-Attribution-Id"] = give('PAYPAL_COMMERCE_ATTRIBUTION_ID');
$this->body = wp_json_encode($requestBody);
}
}
13 changes: 12 additions & 1 deletion src/PaymentGateways/PayPalCommerce/Repositories/PayPalAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Give\PaymentGateways\PayPalCommerce\Repositories;

use Give\Framework\Exceptions\Primitives\Exception;
use Give\Framework\Http\ConnectServer\Client\ConnectClient;
use Give\Helpers\ArrayDataSet;
use Give\Log\Log;
Expand Down Expand Up @@ -133,6 +132,7 @@ public function getTokenFromAuthorizationCode($authCode, $sharedId, $nonce)
/**
* Retrieves a Partner Link for on-boarding
*
* @unreleased Add PayPal-Partner-Attribution-Id header
* @since 3.0.0 Implement $accountType. This parameter is required by GiveWP gateway server.
* @since 2.9.0
*
Expand All @@ -147,6 +147,9 @@ public function getSellerPartnerLink($returnUrl, $accountType)
$this->payPalClient->getMode()
),
[
'headers' => [
'PayPal-Partner-Attribution-Id' => give('PAYPAL_COMMERCE_ATTRIBUTION_ID'),
],
'body' => [
'return_url' => $returnUrl,
'account_type' => $accountType,
Expand All @@ -161,6 +164,7 @@ public function getSellerPartnerLink($returnUrl, $accountType)
/**
* Get seller on-boarding details from seller.
*
* @unreleased Add PayPal-Partner-Attribution-Id header
* @since 2.9.0
*
* @param string $accessToken
Expand All @@ -179,6 +183,9 @@ public function getSellerOnBoardingDetailsFromPayPal($merchantId, $accessToken)
)
),
[
'headers' => [
'PayPal-Partner-Attribution-Id' => give('PAYPAL_COMMERCE_ATTRIBUTION_ID'),
],
'body' => [
'merchant_id' => $merchantId,
'token' => $accessToken,
Expand All @@ -192,6 +199,7 @@ public function getSellerOnBoardingDetailsFromPayPal($merchantId, $accessToken)
/**
* Get seller rest API credentials
*
* @unreleased Add PayPal-Partner-Attribution-Id header
* @since 2.9.0
*
* @param string $accessToken
Expand All @@ -208,6 +216,9 @@ public function getSellerRestAPICredentials($accessToken)
)
),
[
'headers' => [
'PayPal-Partner-Attribution-Id' => give('PAYPAL_COMMERCE_ATTRIBUTION_ID'),
],
'body' => [
'token' => $accessToken,
],
Expand Down
27 changes: 21 additions & 6 deletions src/PaymentGateways/PayPalCommerce/Repositories/PayPalOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,18 @@ public function __construct(PayPalClient $paypalClient, MerchantDetail $merchant
/**
* Approve order.
*
* @unreleased Add PayPal-Partner-Attribution-Id header
* @since 2.9.0
*
* @see https://developer.paypal.com/docs/api/orders/v2/#orders_capture
*
* @return object
* @throws Exception
* @see https://developer.paypal.com/docs/api/orders/v2/#orders_capture
*
*/
public function approveOrder(string $orderId)
{
$request = new OrdersCaptureRequest($orderId);
$request->headers["PayPal-Partner-Attribution-Id"] = give('PAYPAL_COMMERCE_ATTRIBUTION_ID');

try {
return $this->paypalClient->getHttpClient()->execute($request)->result;
Expand Down Expand Up @@ -231,20 +233,23 @@ private function getAmountParameters($array): array
}

/**
* @unreleased Add PayPal-Partner-Attribution-Id header
* @since 3.4.2
*
* @see https://github.com/paypal/Checkout-PHP-SDK/blob/develop/samples/PatchOrder.php
*
* @return mixed
*
* @throws Exception|HttpException|IOException
* @see https://github.com/paypal/Checkout-PHP-SDK/blob/develop/samples/PatchOrder.php
*
*/
public function updateOrderAmount($orderId, array $array)
{
$this->validateCreateOrderArguments($array);

$patchRequest = new OrdersPatchRequest($orderId);

$patchRequest->headers["PayPal-Partner-Attribution-Id"] = give('PAYPAL_COMMERCE_ATTRIBUTION_ID');

$patchRequest->body = [
0 => [
'op' => 'replace',
Expand Down Expand Up @@ -275,16 +280,19 @@ public function updateOrderAmount($orderId, array $array)
}

/**
* @unreleased Add PayPal-Partner-Attribution-Id header
* @since 4.0.0
*
* @see https://developer.paypal.com/docs/api/orders/v2/#orders_patch
*
* @throws Exception|HttpException|IOException
* @see https://developer.paypal.com/docs/api/orders/v2/#orders_patch
*
*/
public function updateApprovedOrder(string $orderId, Money $amount)
{
$patchRequest = new OrdersPatchRequest($orderId);

$patchRequest->headers["PayPal-Partner-Attribution-Id"] = give('PAYPAL_COMMERCE_ATTRIBUTION_ID');

$patchRequest->body = [
[
'op' => 'replace',
Expand Down Expand Up @@ -313,6 +321,7 @@ public function updateApprovedOrder(string $orderId, Money $amount)
/**
* Refunds a processed payment
*
* @unreleased Add PayPal-Partner-Attribution-Id header
* @since 2.9.0
*
* @param $captureId
Expand All @@ -324,6 +333,8 @@ public function refundPayment($captureId)
{
$refund = new CapturesRefundRequest($captureId);

$refund->headers["PayPal-Partner-Attribution-Id"] = give('PAYPAL_COMMERCE_ATTRIBUTION_ID');

try {
return $this->paypalClient->getHttpClient()->execute($refund)->result->id;
} catch (Exception $exception) {
Expand Down Expand Up @@ -366,6 +377,7 @@ private function validateCreateOrderArguments($array)
/**
* Get order details from paypal commerce.
*
* @unreleased Add PayPal-Partner-Attribution-Id header
* @since 2.19.0
*
* @param string $orderId
Expand All @@ -376,6 +388,7 @@ private function validateCreateOrderArguments($array)
public function getOrder($orderId)
{
$orderDetailRequest = new OrdersGetRequest($orderId);
$orderDetailRequest->headers["PayPal-Partner-Attribution-Id"] = give('PAYPAL_COMMERCE_ATTRIBUTION_ID');
$orderDetails = (array)$this->paypalClient->getHttpClient()->execute($orderDetailRequest)->result;

return PayPalOrderModel::fromArray($orderDetails);
Expand All @@ -386,13 +399,15 @@ public function getOrder($orderId)
*
* @see https://developer.paypal.com/docs/api/orders/v2/#orders_get
*
* @unreleased Add PayPal-Partner-Attribution-Id header
* @since 4.0.0
*
* @throws HttpException | IOException
*/
public function getApprovedOrder(string $orderId)
{
$orderDetailRequest = new OrdersGetRequest($orderId);
$orderDetailRequest->headers["PayPal-Partner-Attribution-Id"] = give('PAYPAL_COMMERCE_ATTRIBUTION_ID');

return $this->paypalClient->getHttpClient()->execute($orderDetailRequest)->result;
}
Expand Down
3 changes: 3 additions & 0 deletions src/PaymentGateways/PayPalCommerce/Repositories/Webhooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public function verifyEventSignature($event, $payPalHeaders)
*
* @see https://developer.paypal.com/docs/api/webhooks/v1/#webhooks_post
*
* @unreleased Add PayPal-Partner-Attribution-Id header
* @since 2.32.0 Use PayPal client for rest api calls.
* @since 2.9.0
*
Expand All @@ -135,6 +136,8 @@ static function ($eventType) {
),
]);

$request->headers["PayPal-Partner-Attribution-Id"] = give('PAYPAL_COMMERCE_ATTRIBUTION_ID');

try {
$response = $this->payPalClient
->getHttpClient()
Expand Down