Skip to content

Commit 6c295d3

Browse files
authored
Merge pull request #3 from magebitcom/feature/apple-pay
apple-pay
2 parents 5e471f3 + c252d8b commit 6c295d3

File tree

25 files changed

+1198
-126
lines changed

25 files changed

+1198
-126
lines changed

Api/WebhookInterface.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
/**
3+
* @copyright Copyright (c) 2025 Magebit, Ltd. (https://magebit.com/)
4+
* @author Magebit <[email protected]>
5+
* @license MIT
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace Magebit\CheckoutComPayment\Api;
11+
12+
use Magento\Framework\Exception\LocalizedException;
13+
14+
interface WebhookInterface
15+
{
16+
/**
17+
* Process webhook data
18+
*
19+
* @return void
20+
* @throws LocalizedException
21+
*/
22+
public function process(): void;
23+
}

Block/Payment/Vault.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
namespace Magebit\CheckoutComPayment\Block\Payment;
1111

12-
use Magento\Framework\View\Element\Template\Context;
1312
use Magento\Framework\View\Element\Template;
13+
use Magento\Framework\View\Element\Template\Context;
1414
use CheckoutCom\Magento2\Gateway\Config\Config;
1515
use CheckoutCom\Magento2\Model\Service\VaultHandlerService;
1616
use Magento\Framework\View\Result\PageFactory;

Controller/Onepage/Status.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/**
3+
* @copyright Copyright (c) 2025 Magebit, Ltd. (https://magebit.com/)
4+
* @author Magebit <[email protected]>
5+
* @license MIT
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace Magebit\CheckoutComPayment\Controller\Onepage;
11+
12+
use Magento\Framework\App\Action\HttpGetActionInterface;
13+
use Magento\Framework\Controller\Result\Redirect;
14+
use Magento\Framework\View\Result\Page;
15+
use Magento\Framework\View\Result\PageFactory;
16+
17+
class Status implements HttpGetActionInterface
18+
{
19+
/**
20+
* @param PageFactory $resultPageFactory
21+
*/
22+
public function __construct(
23+
private readonly PageFactory $resultPageFactory
24+
) {
25+
}
26+
27+
/**
28+
* Show payment status page
29+
*
30+
* @return Page|Redirect
31+
*/
32+
public function execute(): Page|Redirect
33+
{
34+
return $this->resultPageFactory->create();
35+
}
36+
}

Helper/Config.php

Lines changed: 115 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
namespace Magebit\CheckoutComPayment\Helper;
1111

1212
use CheckoutCom\Magento2\Model\Config\Backend\Source\ConfigGooglePayButton;
13-
use CheckoutCom\Magento2\Model\Config\Backend\Source\ConfigGooglePayEnvironment;
14-
use CheckoutCom\Magento2\Model\Config\Backend\Source\ConfigGooglePayNetworks;
13+
use CheckoutCom\Magento2\Model\Config\Backend\Source\ConfigApplePayButton;
1514
use JsonException;
1615
use Magento\Customer\Model\Session;
1716
use Magento\Framework\App\Helper\AbstractHelper;
@@ -22,14 +21,6 @@
2221

2322
class Config extends AbstractHelper implements ArgumentInterface
2423
{
25-
/**
26-
* Default allowed GooglePay networks if not configured
27-
*/
28-
private const DEFAULT_CARD_NETWORKS = [
29-
ConfigGooglePayNetworks::CARD_VISA,
30-
ConfigGooglePayNetworks::CARD_MASTERCARD
31-
];
32-
3324
/**
3425
* @param Session $session
3526
* @param Repository $assetRepository
@@ -268,6 +259,19 @@ public function getStoreName(): string
268259
) ?? '';
269260
}
270261

262+
/**
263+
* Get the store country
264+
*
265+
* @return string
266+
*/
267+
public function getStoreCountry(): string
268+
{
269+
return $this->scopeConfig->getValue(
270+
'general/country/default',
271+
ScopeInterface::SCOPE_STORE,
272+
) ?? 'US';
273+
}
274+
271275
/**
272276
* Get Google Pay gateway name
273277
*
@@ -286,7 +290,7 @@ public function getGatewayName(): string
286290
*
287291
* @return string|null
288292
*/
289-
public function getMerchantId(): ?string
293+
public function getGoogleMerchantId(): ?string
290294
{
291295
return $this->scopeConfig->getValue(
292296
'payment/checkoutcom_google_pay/merchant_id',
@@ -304,25 +308,21 @@ public function getEnvironment(): string
304308
return $this->scopeConfig->getValue(
305309
'payment/checkoutcom_google_pay/environment',
306310
ScopeInterface::SCOPE_STORE
307-
) ?? ConfigGooglePayEnvironment::ENVIRONMENT_TEST;
311+
);
308312
}
309313

310314
/**
311-
* Get allowed card networks
315+
* Get Google Pay allowed card networks
312316
*
313317
* @return array
314318
*/
315-
public function getAllowedCardNetworks(): array
319+
public function getGoogleAllowedCardNetworks(): array
316320
{
317321
$networks = $this->scopeConfig->getValue(
318322
'payment/checkoutcom_google_pay/allowed_card_networks',
319323
ScopeInterface::SCOPE_STORE
320324
);
321325

322-
if (empty($networks)) {
323-
return self::DEFAULT_CARD_NETWORKS;
324-
}
325-
326326
return explode(',', $networks);
327327
}
328328

@@ -331,7 +331,7 @@ public function getAllowedCardNetworks(): array
331331
*
332332
* @return int
333333
*/
334-
public function getButtonRadius(): int
334+
public function getGoogleButtonRadius(): int
335335
{
336336
return (int)$this->scopeConfig->getValue(
337337
'payment/checkoutcom_google_pay/button_radius',
@@ -344,11 +344,106 @@ public function getButtonRadius(): int
344344
*
345345
* @return string
346346
*/
347-
public function getButtonStyle(): string
347+
public function getGoogleButtonStyle(): string
348348
{
349349
return $this->scopeConfig->getValue(
350350
'payment/checkoutcom_google_pay/button_style',
351351
ScopeInterface::SCOPE_STORE
352352
) ?? ConfigGooglePayButton::BUTTON_BLACK;
353353
}
354+
355+
/**
356+
* Get Apple Pay Merchant ID
357+
*
358+
* @return string
359+
*/
360+
public function getAppleMerchantID(): string
361+
{
362+
return $this->scopeConfig->getValue(
363+
'payment/checkoutcom_apple_pay/merchant_id',
364+
ScopeInterface::SCOPE_STORE
365+
);
366+
}
367+
368+
/**
369+
* Get Apple Pay supported networks
370+
*
371+
* @return array
372+
*/
373+
public function getAppleSupportedNetworks(): array
374+
{
375+
$networks = $this->scopeConfig->getValue(
376+
'payment/checkoutcom_apple_pay/supported_networks',
377+
ScopeInterface::SCOPE_STORE
378+
);
379+
380+
return explode(',', $networks);
381+
}
382+
383+
/**
384+
* Get Apple Pay merchant capabilities
385+
*
386+
* @return array
387+
*/
388+
public function getAppleMerchantCapabilities(): array
389+
{
390+
$capabilities = $this->scopeConfig->getValue(
391+
'payment/checkoutcom_apple_pay/merchant_capabilities',
392+
ScopeInterface::SCOPE_STORE
393+
);
394+
395+
return explode(',', $capabilities);
396+
}
397+
398+
/**
399+
* Get Apple Pay button style
400+
*
401+
* @return string
402+
*/
403+
public function getAppleButtonStyle(): string
404+
{
405+
return $this->scopeConfig->getValue(
406+
'payment/checkoutcom_apple_pay/button_style',
407+
ScopeInterface::SCOPE_STORE
408+
) ?? ConfigApplePayButton::BUTTON_BLACK;
409+
}
410+
411+
/**
412+
* Apple Pay button corner radius
413+
*
414+
* @return int
415+
*/
416+
public function getAppleButtonRadius(): int
417+
{
418+
return (int)$this->scopeConfig->getValue(
419+
'payment/checkoutcom_apple_pay/button_radius',
420+
ScopeInterface::SCOPE_STORE,
421+
) ?? 8;
422+
}
423+
424+
/**
425+
* Apple Pay button height
426+
*
427+
* @return int
428+
*/
429+
public function getAppleButtonHeight(): int
430+
{
431+
return (int)$this->scopeConfig->getValue(
432+
'payment/checkoutcom_apple_pay/button_height',
433+
ScopeInterface::SCOPE_STORE,
434+
) ?? 40;
435+
}
436+
437+
/**
438+
* Webhook authorization header key
439+
*
440+
* @return string
441+
*/
442+
public function getAuthHeaderKey(): string
443+
{
444+
return $this->scopeConfig->getValue(
445+
'settings/checkoutcom_configuration/private_shared_key',
446+
ScopeInterface::SCOPE_STORE
447+
);
448+
}
354449
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
/**
3+
* @copyright Copyright (c) 2025 Magebit, Ltd. (https://magebit.com/)
4+
* @author Magebit <[email protected]>
5+
* @license MIT
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace Magebit\CheckoutComPayment\Magewire\Payment\Method;
11+
12+
use Magebit\CheckoutComPayment\Model\Magewire\Payment\CheckoutComPlaceOrderService;
13+
use Magebit\CheckoutComPayment\ViewModel\Data;
14+
use Magento\Checkout\Model\Session as CheckoutSession;
15+
use Magento\Framework\Exception\LocalizedException;
16+
use Magento\Framework\Exception\NoSuchEntityException;
17+
use Magewirephp\Magewire\Component;
18+
19+
class CheckoutComApplePay extends Component
20+
{
21+
/**
22+
* Define component's listeners for checkout events
23+
*
24+
* @var array
25+
*/
26+
protected $listeners = [
27+
'shipping_method_selected' => 'refresh',
28+
'coupon_code_applied' => 'refresh',
29+
'coupon_code_revoked' => 'refresh',
30+
];
31+
32+
/**
33+
* @var float
34+
*/
35+
public float $amount = 0.0;
36+
37+
/**
38+
* Apple Pay session storage constants
39+
*/
40+
public const PAYMENT_TOKEN = 'checkout_com_apple_pay_token';
41+
public const PAYMENT_SOURCE = 'checkout_com_apple_pay_source';
42+
43+
/**
44+
* @param CheckoutSession $checkoutSession
45+
* @param CheckoutComPlaceOrderService $placeOrderService
46+
* @param Data $checkoutViewModel
47+
*/
48+
public function __construct(
49+
private readonly CheckoutSession $checkoutSession,
50+
private readonly CheckoutComPlaceOrderService $placeOrderService,
51+
private readonly Data $checkoutViewModel
52+
) {
53+
}
54+
55+
/**
56+
* Initialize component with cart details
57+
*
58+
* @return void
59+
*/
60+
public function boot(): void
61+
{
62+
$this->setCartDetails();
63+
}
64+
65+
/**
66+
* Set all cart details needed for placing order
67+
*
68+
* @return void
69+
*/
70+
protected function setCartDetails(): void
71+
{
72+
$this->amount = $this->checkoutViewModel->getTotal();
73+
}
74+
75+
/**
76+
* Set the Apple Pay token with related data
77+
*
78+
* @param array $tokenData
79+
* @return void
80+
*/
81+
public function setPaymentToken(array $tokenData): void
82+
{
83+
$this->checkoutSession->setData(self::PAYMENT_TOKEN, $tokenData);
84+
$this->checkoutSession->setData(self::PAYMENT_SOURCE, 'checkoutcom_apple_pay');
85+
}
86+
87+
/**
88+
* Place order and handle redirection
89+
*
90+
* @throws NoSuchEntityException
91+
* @throws LocalizedException
92+
* @return void
93+
*/
94+
public function placeOrder(): void
95+
{
96+
$quote = $this->checkoutSession->getQuote();
97+
$orderId = $this->placeOrderService->placeOrder($quote);
98+
99+
if ($orderId) {
100+
$redirectUrl = $this->placeOrderService->getRedirectUrl($quote, $orderId);
101+
$this->redirect($redirectUrl, null, true);
102+
}
103+
}
104+
}

0 commit comments

Comments
 (0)