Skip to content

Commit

Permalink
Merge pull request #292 from OXID-eSales/PSPAYPAL-684_ApplePay
Browse files Browse the repository at this point in the history
Pspaypal 684 apple pay
  • Loading branch information
mariolorenz authored Jun 6, 2024
2 parents 5854c1d + e1c4b43 commit ca5dbf9
Show file tree
Hide file tree
Showing 21 changed files with 812 additions and 12 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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.4.1] - 2024-??-??
## [2.5.0] - 2024-??-??

### FIX

Expand All @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### NEW
- PayPal-Request-Id based on serialized body, no extra PayPal-Request-Id necessary anymore
- Introduce GooglePay-Payment
- Introduce ApplePay-Payment
- use PayPal-Client v2.0.14
- add Default-Shippingcosts for PP-Express to prevent overcharge.

Expand Down
17 changes: 16 additions & 1 deletion metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,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.4.1-rc.1',
'version' => '2.5.0-rc.1',
'author' => 'OXID eSales AG',
'url' => 'https://www.oxid-esales.com',
'email' => 'info@oxid-esales.com',
Expand Down Expand Up @@ -106,6 +106,7 @@
'modules/osc/paypal/pui_flow.tpl' => 'osc/paypal/views/tpl/flow/page/checkout/pui.tpl',
'modules/osc/paypal/pui_wave.tpl' => 'osc/paypal/views/tpl/wave/page/checkout/pui.tpl',
'modules/osc/paypal/pui_fraudnet.tpl' => 'osc/paypal/views/tpl/shared/page/checkout/pui_fraudnet.tpl',
'modules/osc/paypal/apple_pay.tpl' => 'osc/paypal/views/tpl/shared/page/checkout/apple_pay.tpl',
'modules/osc/paypal/shipping_and_payment_flow.tpl' => 'osc/paypal/views/tpl/flow/page/checkout/shipping_and_payment.tpl',
'modules/osc/paypal/shipping_and_payment_wave.tpl' => 'osc/paypal/views/tpl/wave/page/checkout/shipping_and_payment.tpl',
'modules/osc/paypal/shipping_and_payment_paypal_flow.tpl' => 'osc/paypal/views/tpl/flow/page/checkout/shipping_and_payment_paypal.tpl',
Expand Down Expand Up @@ -136,6 +137,8 @@
// PSPAYPAL-685 Installment banners
'modules/osc/paypal/googlepay.tpl' => 'osc/paypal/views/tpl/shared/googlepay.tpl',

'modules/osc/paypal/applepay.tpl' => 'osc/paypal/views/tpl/shared/applepay.tpl',

//PSPAYPAL-680 Vaulting
'modules/osc/paypal/account_vaulting_paypal.tpl' => 'osc/paypal/views/tpl/shared/page/account/account_vaulting_paypal.tpl',
'modules/osc/paypal/account_vaulting_card.tpl' => 'osc/paypal/views/tpl/shared/page/account/account_vaulting_card.tpl',
Expand Down Expand Up @@ -475,6 +478,12 @@
'value' => false,
'group' => null
],
[
'name' => 'oscPayPalApplePayEligibility',
'type' => 'bool',
'value' => false,
'group' => null
],
[
'name' => 'oscPayPalGooglePayEligibility',
'type' => 'bool',
Expand All @@ -499,6 +508,12 @@
'value' => false,
'group' => null
],
[
'name' => 'oscPayPalSandboxApplePayEligibility',
'type' => 'bool',
'value' => false,
'group' => null
],
[
'name' => 'oscPayPalSandboxGooglePayEligibility',
'type' => 'bool',
Expand Down
114 changes: 113 additions & 1 deletion src/Controller/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
use OxidSolutionCatalysts\PayPal\Traits\ServiceContainer;
use OxidSolutionCatalysts\PayPalApi\Exception\ApiException;
use OxidSolutionCatalysts\PayPalApi\Model\Orders\Order as ApiOrderModel;
use OxidSolutionCatalysts\PayPalApi\Model\Orders\ConfirmOrderRequest;
use OxidSolutionCatalysts\PayPalApi\Model\Orders\Order as PayPalApiModelOrder;
use OxidSolutionCatalysts\PayPalApi\Model\Orders\OrderCaptureRequest;
use OxidSolutionCatalysts\PayPalApi\Model\Orders\PaymentSource;

/**
* Class OrderController
Expand Down Expand Up @@ -371,7 +373,7 @@ public function captureAcdcOrder(): void
$result = [
'location' => [
'cl=order&fnc=finalizeacdc'
]
]
];
//track status in session
Registry::getSession()->setVariable(Constants::SESSION_ACDC_PAYPALORDER_STATUS, $response->status);
Expand All @@ -386,7 +388,117 @@ public function captureAcdcOrder(): void

$this->outputJson($result);
}
public function createApplePayOrder(): void
{
try {
$paymentService = $this->getServiceFromContainer(PaymentService::class);
$paymentService->removeTemporaryOrder();
Registry::getSession()->setVariable('sess_challenge', $this->getUtilsObjectInstance()->generateUID());

$_POST['sDeliveryAddressMD5'] = $this->getDeliveryAddressMD5();
$status = $this->execute();
} catch (Exception $exception) {
/** @var Logger $logger */
$logger = $this->getServiceFromContainer(Logger::class);
$logger->log('error', $exception->getMessage(), [$exception]);
$this->outputJson(['error' => 'failed to execute shop order' . $exception->getMessage()]);
return;
}

$response = $paymentService->doCreatePatchedOrder(
Registry::getSession()->getBasket()
);
if (!($paypalOrderId = $response['id'])) {
$this->outputJson(['error' => 'cannot create paypal order']);
return;
}

if (!$status) {
$response = ['error' => 'unexpected order status ' . $status];
$paymentService->removeTemporaryOrder();
} else {
PayPalSession::storePayPalOrderId($paypalOrderId);
$sessionOrderId = (string) Registry::getSession()->getVariable('sess_challenge');
$payPalOrder = $paymentService->getPayPalCheckoutOrder($sessionOrderId, $paypalOrderId);
$payPalOrder->setStatus($response['status']);
$payPalOrder->save();
}


$this->outputJson($response);
}
public function captureApplePayOrder()
{
$orderId = (string) Registry::getRequest()->getRequestEscapedParameter('orderID');
$orderService = Registry::get(ServiceFactory::class)->getOrderService();
$sessionOrderId = (string) Registry::getSession()->getVariable('sess_challenge');
$checkoutOrderId = (string) PayPalSession::getCheckoutOrderId();
$request = new OrderCaptureRequest();
$logger = $this->getServiceFromContainer(Logger::class);
try {
/** @var $result ApiOrderModel */
$result = $orderService->capturePaymentForOrder(
'',
$orderId,
$request,
'',
);
} catch (ApiException $exception) {
$logger = $this->getServiceFromContainer(Logger::class);
$logger->log('error', $exception->getMessage(), [$exception]);

throw oxNew(StandardException::class, 'OSC_PAYPAL_ORDEREXECUTION_ERROR' . $exception->getMessage());
}

try {
$order = oxNew(EshopModelOrder::class);
$order->setId($sessionOrderId);
$order->load($sessionOrderId);

$result = [
'location' => [
'cl=order&fnc=finalizeapplepay'
]
];
//track status in session
Registry::getSession()->setVariable('Sessionapplepay', $sessionOrderId);
Registry::getSession()->setVariable('applepayOrderId', $orderId);
} catch (Exception $exception) {
$logger->log(
'debug',
$exception->getMessage(),
[$exception]
);
$this->getServiceFromContainer(PaymentService::class)->removeTemporaryOrder();
}

$this->outputJson($result);
}
public function finalizeApplePay(): string
{
$sessionOrderId = Registry::getSession()->getVariable('Sessionapplepay');
$sessionGooglePayOrderId = Registry::getSession()->getVariable('applepayOrderId'); // paypal-checkout-session
$forceFetchDetails = (bool) Registry::getRequest()->getRequestParameter('fallbackfinalize');

try {
$order = oxNew(EshopModelOrder::class);
$order->load($sessionOrderId);
$order->finalizeOrderAfterExternalPayment($sessionGooglePayOrderId, $forceFetchDetails);
$goNext = 'thankyou';
} catch (Exception $exception) {
/** @var Logger $logger */
$logger = $this->getServiceFromContainer(Logger::class);
$logger->log(
'error',
'failure during finalizeOrderAfterExternalPayment',
[$exception]
);
$this->cancelpaypalsession('cannot finalize order');
$goNext = 'payment?payerror=2';
}

return $goNext;
}
public function finalizepaypalsession(): string
{
$standardRequestId = (string) Registry::getRequest()->getRequestParameter('token');
Expand Down
Loading

0 comments on commit ca5dbf9

Please sign in to comment.