Skip to content

Commit

Permalink
Merge pull request #241 from OXID-eSales/688-order-number-sent-to-paypal
Browse files Browse the repository at this point in the history
688 Order number sent to PayPal transaction as custom value
  • Loading branch information
mariolorenz authored Jan 5, 2024
2 parents 3cc5103 + 65d5b13 commit 2a8418d
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ 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.3.4] - 2024-??-??

- Transfer OXID-Ordernumber to PayPal

## [2.3.3] - 2023-11-16

- [0007549](https://bugs.oxid-esales.com/view.php?id=7549): Optional field in shop admin -> refund "Note to buyer" is transmitted to PayPal
Expand Down
2 changes: 1 addition & 1 deletion metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
'en' => 'Use of the online payment service from PayPal. Documentation: <a href="https://docs.oxid-esales.com/modules/paypal-checkout/en/latest/" target="_blank">PayPal Checkout</a>'
],
'thumbnail' => 'out/img/paypal.png',
'version' => '2.3.3',
'version' => '2.3.4-rc.1',
'author' => 'OXID eSales AG',
'url' => 'https://www.oxid-esales.com',
'email' => 'info@oxid-esales.com',
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/ProxyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ public function createOrder()
null,
'',
'',
'',
Constants::PAYPAL_PARTNER_ATTRIBUTION_ID_PPCP,
null,
null,
false,
false
false,
null
);

if ($response->id) {
Expand Down
6 changes: 3 additions & 3 deletions src/Core/OrderRequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class OrderRequestFactory
* @param Basket $basket
* @param string $intent Order::INTENT_CAPTURE or Order::INTENT_AUTHORIZE constant values
* @param null|string $userAction USER_ACTION_CONTINUE constant values
* @param null|string $transactionId transaction id
* @param null|string $customId custom id reference
* @param null|string $processingInstruction processing instruction
* @param null|string $paymentSource Payment-Source Name
* @param null|string $invoiceId custom invoice number
Expand All @@ -81,7 +81,7 @@ public function getRequest(
Basket $basket,
string $intent,
?string $userAction = null,
?string $transactionId = null,
?string $customId = null,
?string $processingInstruction = null,
?string $paymentSource = null,
?string $invoiceId = null,
Expand All @@ -98,7 +98,7 @@ public function getRequest(
$request->payer = $this->getPayer();
}

$request->purchase_units = $this->getPurchaseUnits($transactionId, $invoiceId, $withArticles);
$request->purchase_units = $this->getPurchaseUnits($customId, $invoiceId, $withArticles);

if ($userAction || $returnUrl || $cancelUrl) {
$request->application_context = $this->getApplicationContext(
Expand Down
2 changes: 2 additions & 0 deletions src/Model/PaymentGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ protected function doExecutePuiPayment(EshopModelOrder $order): bool

$success = false;
try {
//order number must be resolved before requesting payment
$order->setOrderNumber();
$success = $paymentService->doExecutePuiPayment(
$order,
Registry::getSession()->getBasket(),
Expand Down
30 changes: 19 additions & 11 deletions src/Service/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ public function doCreatePayPalOrder(
string $processingInstruction = null,
string $paymentSource = null,
string $payPalClientMetadataId = '',
string $payPalRequestId = '',
string $payPalPartnerAttributionId = '',
string $returnUrl = null,
string $cancelUrl = null,
bool $withArticles = true,
bool $setProvidedAddress = true
bool $setProvidedAddress = true,
?EshopModelOrder $order = null
#): ?ApiModelOrder
) {
//TODO return value
Expand All @@ -127,7 +127,7 @@ public function doCreatePayPalOrder(
$basket,
$intent,
$userAction,
null,
$order instanceof EshopModelOrder ? $order->getFieldData('oxordernr') : null,
$processingInstruction,
$paymentSource,
null,
Expand All @@ -145,7 +145,7 @@ public function doCreatePayPalOrder(
$payPalPartnerAttributionId,
$payPalClientMetadataId,
'return=minimal',
$payPalRequestId
$order instanceof EshopModelOrder ? $order->getId() : null
);
} catch (ApiException $exception) {
$this->moduleLogger->error("Api error on order create call. " .
Expand All @@ -172,7 +172,6 @@ public function doCreatePatchedOrder(
null,
null,
'',
'',
Constants::PAYPAL_PARTNER_ATTRIBUTION_ID_PPCP,
null,
null,
Expand Down Expand Up @@ -309,8 +308,16 @@ public function doCapturePayPalOrder(
$result = $this->fetchOrderFields($checkoutOrderId);
} else {
$request = new OrderCaptureRequest();
//order number must be resolved before order patching
$order->setOrderNumber();
try {
/** @var ApiOrderModel */
//Patching the order with OXID order number as custom value
$this->doPatchPayPalOrder(
Registry::getSession()->getBasket(),
$checkoutOrderId,
$order->getFieldData('oxordernr')
);
/** @var $result ApiOrderModel */
$result = $orderService->capturePaymentForOrder(
'',
$checkoutOrderId,
Expand Down Expand Up @@ -345,7 +352,6 @@ public function doCapturePayPalOrder(
);

if ($result instanceof Order && $order->isPayPalOrderCompleted($result)) {
$order->setOrderNumber();
$order->markOrderPaid();
$order->setTransId((string)$payPalTransactionId);
}
Expand Down Expand Up @@ -530,7 +536,6 @@ public function doExecuteStandardPayment(
null,
null,
'',
'',
Constants::PAYPAL_PARTNER_ATTRIBUTION_ID_PPCP,
$returnUrl,
$cancelUrl,
Expand Down Expand Up @@ -574,7 +579,6 @@ public function doCreateUAPMOrder(EshopModelBasket $basket): string
null,
null,
'',
'',
Constants::PAYPAL_PARTNER_ATTRIBUTION_ID_PPCP,
null,
null,
Expand All @@ -599,8 +603,12 @@ public function doExecutePuiPayment(
Constants::PAYPAL_PUI_PROCESSING_INSTRUCTIONS,
PayPalDefinitions::PUI_REQUEST_PAYMENT_SOURCE_NAME,
$payPalClientMetadataId,
$order->getId(),
Constants::PAYPAL_PARTNER_ATTRIBUTION_ID_PPCP
Constants::PAYPAL_PARTNER_ATTRIBUTION_ID_PPCP,
null,
null,
true,
true,
$order
);
$payPalOrderId = $result->id;
} catch (UserPhoneException $e) {
Expand Down

0 comments on commit 2a8418d

Please sign in to comment.