Skip to content

Commit

Permalink
Merge pull request #16 from OXID-eSales/PSPAYPAL-750-PayPal-Request-I…
Browse files Browse the repository at this point in the history
…d-in-any-call

Pspaypal 750 pay pal request id in any call
  • Loading branch information
mariolorenz authored Apr 9, 2024
2 parents 5a0005e + 14eb2d4 commit 5a016a6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 30 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [2.0.13] -2024-04-09

- PayPal-Request-Id based on serialized body, no extra PayPal-Request-Id necessary anymore

## [2.0.12] -2024-03-19

- introduce central log functionality

## [2.0.11] -2024-03-15

- remove 500-redirect if some API Calls not work correctly
Expand Down
18 changes: 3 additions & 15 deletions generated/Service/Orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Orders extends BaseService
* @throws ApiException
* @return Order
*/
public function createOrder(OrderRequest $order, $payPalPartnerAttributionId, $payPalClientMetadataId, $prefer = 'return=minimal', $payPalRequestId = ''): Order
public function createOrder(OrderRequest $order, $payPalPartnerAttributionId, $payPalClientMetadataId, $prefer = 'return=minimal'): Order
{
$path = "/orders";

Expand All @@ -47,10 +47,6 @@ public function createOrder(OrderRequest $order, $payPalPartnerAttributionId, $p
$headers['PayPal-Client-Metadata-Id'] = $payPalClientMetadataId;
$headers['Prefer'] = $prefer;

if ($payPalRequestId) {
$headers['PayPal-Request-Id'] = $payPalRequestId;
}

$body = json_encode($order, true);
$response = $this->send('POST', $path, [], $headers, $body);
$jsonData = json_decode($response->getBody(), true);
Expand Down Expand Up @@ -224,7 +220,7 @@ public function confirmTheOrder($payPalClientMetadataId, $id, ConfirmOrderReques
* @throws ApiException
* @return Order
*/
public function authorizePaymentForOrder($payPalClientMetadataId, $id, OrderAuthorizeRequest $authorizeRequest, $payPalAuthAssertion, string $payPalPartnerAttributionId = '', $payPalRequestId = '' , $prefer = 'return=minimal'): Order
public function authorizePaymentForOrder($payPalClientMetadataId, $id, OrderAuthorizeRequest $authorizeRequest, $payPalAuthAssertion, string $payPalPartnerAttributionId = '', $prefer = 'return=minimal'): Order
{
$path = "/orders/{$id}/authorize";

Expand All @@ -234,10 +230,6 @@ public function authorizePaymentForOrder($payPalClientMetadataId, $id, OrderAuth
$headers['PayPal-Auth-Assertion'] = $payPalAuthAssertion;
$headers['Prefer'] = $prefer;

if ($payPalRequestId) {
$headers['PayPal-Request-Id'] = $payPalRequestId;
}

if ($payPalPartnerAttributionId) {
$headers['PayPal-Partner-Attribution-Id'] = $payPalPartnerAttributionId;
}
Expand Down Expand Up @@ -276,7 +268,7 @@ public function authorizePaymentForOrder($payPalClientMetadataId, $id, OrderAuth
* @throws ApiException
* @return Order
*/
public function capturePaymentForOrder($payPalClientMetadataId, $id, OrderCaptureRequest $orderCaptureRequest, $payPalAuthAssertion, string $payPalPartnerAttributionId = '', $payPalRequestId = '', $prefer = 'return=minimal'): Order
public function capturePaymentForOrder($payPalClientMetadataId, $id, OrderCaptureRequest $orderCaptureRequest, $payPalAuthAssertion, string $payPalPartnerAttributionId = '', $prefer = 'return=minimal'): Order
{
$path = "/orders/{$id}/capture";

Expand All @@ -286,10 +278,6 @@ public function capturePaymentForOrder($payPalClientMetadataId, $id, OrderCaptur
$headers['PayPal-Auth-Assertion'] = $payPalAuthAssertion;
$headers['Prefer'] = $prefer;

if ($payPalRequestId) {
$headers['PayPal-Request-Id'] = $payPalRequestId;
}

if ($payPalPartnerAttributionId) {
$headers['PayPal-Partner-Attribution-Id'] = $payPalPartnerAttributionId;
}
Expand Down
18 changes: 3 additions & 15 deletions generated/Service/Payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,14 @@ public function showDetailsForAuthorizedPayment($authorizationId): Authorization
* @throws ApiException
* @return Capture
*/
public function captureAuthorizedPayment($authorizationId, CaptureRequest $capture, string $payPalPartnerAttributionId = '', $payPalRequestId = '',$prefer = 'return=minimal'): Capture
public function captureAuthorizedPayment($authorizationId, CaptureRequest $capture, string $payPalPartnerAttributionId = '',$prefer = 'return=minimal'): Capture
{
$path = "/authorizations/{$authorizationId}/capture";

$headers = [];
$headers['Content-Type'] = 'application/json';
$headers['Prefer'] = $prefer;

if ($payPalRequestId) {
$headers['PayPal-Request-Id'] = $payPalRequestId;
}

if ($payPalPartnerAttributionId) {
$headers['PayPal-Partner-Attribution-Id'] = $payPalPartnerAttributionId;
}
Expand Down Expand Up @@ -140,18 +136,14 @@ public function captureAuthorizedPayment($authorizationId, CaptureRequest $captu
* @return Authorization
*@throws ApiException
*/
public function reauthorizeAuthorizedPayment($authorizationId, ReauthorizeRequest $reauthorizeRequest, string $payPalPartnerAttributionId = '', $payPalRequestId = '',$prefer = 'return=minimal'): Authorization
public function reauthorizeAuthorizedPayment($authorizationId, ReauthorizeRequest $reauthorizeRequest, string $payPalPartnerAttributionId = '', $prefer = 'return=minimal'): Authorization
{
$path = "/authorizations/{$authorizationId}/reauthorize";

$headers = [];
$headers['Content-Type'] = 'application/json';
$headers['Prefer'] = $prefer;

if ($payPalRequestId) {
$headers['PayPal-Request-Id'] = $payPalRequestId;
}

if ($payPalPartnerAttributionId) {
$headers['PayPal-Partner-Attribution-Id'] = $payPalPartnerAttributionId;
}
Expand Down Expand Up @@ -270,7 +262,7 @@ public function showCapturedPaymentDetails($captureId): Capture
* @throws ApiException
* @return Refund
*/
public function refundCapturedPayment($captureId, RefundRequest $refundRequest, $payPalAuthAssertion, string $payPalPartnerAttributionId = '', $payPalRequestId = '',$prefer = 'return=minimal'): Refund
public function refundCapturedPayment($captureId, RefundRequest $refundRequest, $payPalAuthAssertion, string $payPalPartnerAttributionId = '', $prefer = 'return=minimal'): Refund
{
$path = "/captures/{$captureId}/refund";

Expand All @@ -279,10 +271,6 @@ public function refundCapturedPayment($captureId, RefundRequest $refundRequest,
$headers['PayPal-Auth-Assertion'] = $payPalAuthAssertion;
$headers['Prefer'] = $prefer;

if ($payPalRequestId) {
$headers['PayPal-Request-Id'] = $payPalRequestId;
}

if ($payPalPartnerAttributionId) {
$headers['PayPal-Partner-Attribution-Id'] = $payPalPartnerAttributionId;
}
Expand Down
5 changes: 5 additions & 0 deletions src/Service/BaseService.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ protected function send($method, $path, $params = [], $headers = [], $body = nul
$path = "$path?$q";
}
$fullPath = $this->basePath . $path;

if ($body) {
$headers['PayPal-Request-Id'] = md5(serialize($body));
}

$request = $this->client->createRequest($method, $fullPath, $headers, $body);

$logger->log('debug', 'PayPal SEND path ' . $path);
Expand Down

0 comments on commit 5a016a6

Please sign in to comment.