Skip to content

apple-pay #3

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
122 changes: 102 additions & 20 deletions Helper/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
namespace Magebit\CheckoutComPayment\Helper;

use CheckoutCom\Magento2\Model\Config\Backend\Source\ConfigGooglePayButton;
use CheckoutCom\Magento2\Model\Config\Backend\Source\ConfigGooglePayEnvironment;
use CheckoutCom\Magento2\Model\Config\Backend\Source\ConfigGooglePayNetworks;
use CheckoutCom\Magento2\Model\Config\Backend\Source\ConfigApplePayButton;
use JsonException;
use Magento\Customer\Model\Session;
use Magento\Framework\App\Helper\AbstractHelper;
Expand All @@ -22,14 +21,6 @@

class Config extends AbstractHelper implements ArgumentInterface
{
/**
* Default allowed GooglePay networks if not configured
*/
private const DEFAULT_CARD_NETWORKS = [
ConfigGooglePayNetworks::CARD_VISA,
ConfigGooglePayNetworks::CARD_MASTERCARD
];

/**
* @param Session $session
* @param Repository $assetRepository
Expand Down Expand Up @@ -268,6 +259,19 @@ public function getStoreName(): string
) ?? '';
}

/**
* Get the store country
*
* @return string
*/
public function getStoreCountry(): string
{
return $this->scopeConfig->getValue(
'general/country/default',
ScopeInterface::SCOPE_STORE,
) ?? 'US';
}

/**
* Get Google Pay gateway name
*
Expand All @@ -286,7 +290,7 @@ public function getGatewayName(): string
*
* @return string|null
*/
public function getMerchantId(): ?string
public function getGoogleMerchantId(): ?string
{
return $this->scopeConfig->getValue(
'payment/checkoutcom_google_pay/merchant_id',
Expand All @@ -304,25 +308,21 @@ public function getEnvironment(): string
return $this->scopeConfig->getValue(
'payment/checkoutcom_google_pay/environment',
ScopeInterface::SCOPE_STORE
) ?? ConfigGooglePayEnvironment::ENVIRONMENT_TEST;
);
}

/**
* Get allowed card networks
* Get Google Pay allowed card networks
*
* @return array
*/
public function getAllowedCardNetworks(): array
public function getGoogleAllowedCardNetworks(): array
{
$networks = $this->scopeConfig->getValue(
'payment/checkoutcom_google_pay/allowed_card_networks',
ScopeInterface::SCOPE_STORE
);

if (empty($networks)) {
return self::DEFAULT_CARD_NETWORKS;
}

return explode(',', $networks);
}

Expand All @@ -331,7 +331,7 @@ public function getAllowedCardNetworks(): array
*
* @return int
*/
public function getButtonRadius(): int
public function getGoogleButtonRadius(): int
{
return (int)$this->scopeConfig->getValue(
'payment/checkoutcom_google_pay/button_radius',
Expand All @@ -344,11 +344,93 @@ public function getButtonRadius(): int
*
* @return string
*/
public function getButtonStyle(): string
public function getGoogleButtonStyle(): string
{
return $this->scopeConfig->getValue(
'payment/checkoutcom_google_pay/button_style',
ScopeInterface::SCOPE_STORE
) ?? ConfigGooglePayButton::BUTTON_BLACK;
}

/**
* Get Apple Pay Merchant ID
*
* @return string
*/
public function getAppleMerchantID(): string
{
return $this->scopeConfig->getValue(
'payment/checkoutcom_apple_pay/merchant_id',
ScopeInterface::SCOPE_STORE
);
}

/**
* Get Apple Pay supported networks
*
* @return array
*/
public function getAppleSupportedNetworks(): array
{
$networks = $this->scopeConfig->getValue(
'payment/checkoutcom_apple_pay/supported_networks',
ScopeInterface::SCOPE_STORE
);

return explode(',', $networks);
}

/**
* Get Apple Pay merchant capabilities
*
* @return array
*/
public function getAppleMerchantCapabilities(): array
{
$capabilities = $this->scopeConfig->getValue(
'payment/checkoutcom_apple_pay/merchant_capabilities',
ScopeInterface::SCOPE_STORE
);

return explode(',', $capabilities);
}

/**
* Get Apple Pay button style
*
* @return string
*/
public function getAppleButtonStyle(): string
{
return $this->scopeConfig->getValue(
'payment/checkoutcom_apple_pay/button_style',
ScopeInterface::SCOPE_STORE
) ?? ConfigApplePayButton::BUTTON_BLACK;
}

/**
* Apple Pay button corner radius
*
* @return int
*/
public function getAppleButtonRadius(): int
{
return (int)$this->scopeConfig->getValue(
'payment/checkoutcom_apple_pay/button_radius',
ScopeInterface::SCOPE_STORE,
) ?? 8;
}

/**
* Apple Pay button height
*
* @return int
*/
public function getAppleButtonHeight(): int
{
return (int)$this->scopeConfig->getValue(
'payment/checkoutcom_apple_pay/button_height',
ScopeInterface::SCOPE_STORE,
) ?? 40;
}
}
104 changes: 104 additions & 0 deletions Magewire/Payment/Method/CheckoutComApplePay.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php
/**
* @copyright Copyright (c) 2025 Magebit, Ltd. (https://magebit.com/)
* @author Magebit <info@magebit.com>
* @license MIT
*/

declare(strict_types=1);

namespace Magebit\CheckoutComPayment\Magewire\Payment\Method;

use Magebit\CheckoutComPayment\Model\Magewire\Payment\CheckoutComPlaceOrderService;
use Magebit\CheckoutComPayment\ViewModel\Data;
use Magento\Checkout\Model\Session as CheckoutSession;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magewirephp\Magewire\Component;

class CheckoutComApplePay extends Component
{
/**
* Define component's listeners for checkout events
*
* @var array
*/
protected $listeners = [
'shipping_method_selected' => 'refresh',
'coupon_code_applied' => 'refresh',
'coupon_code_revoked' => 'refresh',
];

/**
* @var float
*/
public float $amount = 0.0;

/**
* Apple Pay session storage constants
*/
public const PAYMENT_TOKEN = 'checkout_com_apple_pay_token';
public const PAYMENT_SOURCE = 'checkout_com_apple_pay_source';

/**
* @param CheckoutSession $checkoutSession
* @param CheckoutComPlaceOrderService $placeOrderService
* @param Data $checkoutViewModel
*/
public function __construct(
private readonly CheckoutSession $checkoutSession,
private readonly CheckoutComPlaceOrderService $placeOrderService,
private readonly Data $checkoutViewModel
) {
}

/**
* Initialize component with cart details
*
* @return void
*/
public function boot(): void
{
$this->setCartDetails();
}

/**
* Set all cart details needed for placing order
*
* @return void
*/
protected function setCartDetails(): void
{
$this->amount = $this->checkoutViewModel->getTotal();
}

/**
* Set the Apple Pay token with related data
*
* @param array $tokenData
* @return void
*/
public function setPaymentToken(array $tokenData): void
{
$this->checkoutSession->setData(self::PAYMENT_TOKEN, $tokenData);
$this->checkoutSession->setData(self::PAYMENT_SOURCE, 'checkoutcom_apple_pay');
}

/**
* Place order and handle redirection
*
* @throws NoSuchEntityException
* @throws LocalizedException
* @return void
*/
public function placeOrder(): void
{
$quote = $this->checkoutSession->getQuote();
$orderId = $this->placeOrderService->placeOrder($quote);

if ($orderId) {
$redirectUrl = $this->placeOrderService->getRedirectUrl($quote, $orderId);
$this->redirect($redirectUrl, null, true);
}
}
}
6 changes: 6 additions & 0 deletions Model/Magewire/Payment/CheckoutComPlaceOrderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Magebit\CheckoutComPayment\Magewire\Payment\Method\CheckoutComApm;
use Magebit\CheckoutComPayment\Magewire\Payment\Method\CheckoutComCard;
use Magebit\CheckoutComPayment\Magewire\Payment\Method\CheckoutComGooglePay;
use Magebit\CheckoutComPayment\Magewire\Payment\Method\CheckoutComApplePay;
use Magebit\CheckoutComPayment\Magewire\Payment\Method\CheckoutComVault;
use Hyva\Checkout\Model\Magewire\Payment\AbstractOrderData;
use Hyva\Checkout\Model\Magewire\Payment\AbstractPlaceOrderService;
Expand Down Expand Up @@ -119,6 +120,11 @@ public function placeOrder(Quote $quote): int
'cardToken' => $this->session->getData(CheckoutComGooglePay::PAYMENT_TOKEN),
'source' => $this->session->getData(CheckoutComGooglePay::PAYMENT_SOURCE)
],
'checkoutcom_apple_pay' => [
'methodId' => 'checkoutcom_apple_pay',
'cardToken' => $this->session->getData(CheckoutComApplePay::PAYMENT_TOKEN),
'source' => $this->session->getData(CheckoutComApplePay::PAYMENT_SOURCE)
],
'checkoutcom_apm' => $this->getApmData(),
default => []
};
Expand Down
24 changes: 19 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ bin/magento module:enable Magebit_CheckoutComPayment && bin/magento setup:upgrad
- [x] Card Payments (Multiple iframes)
- [X] Vault
- [x] Google Pay
- [x] MB PAY
- [x] Apple Pay
- [x] Checkout Page
- [ ] Cart
- [ ] Minicart
- [x] Alternative payment methods
- [X] MB PAY

### Functionality that is currently not supported:
* Adding a new Stored Card from My Account -> Stored Payment Methods
Expand All @@ -27,21 +32,30 @@ bin/magento module:enable Magebit_CheckoutComPayment && bin/magento setup:upgrad
* Card Payments -> Display Card Icons

### Payment methods the currently are not supported:
* Apple Pay Payments
* Klarna (NAS)
* Paypal Payments (NAS)
* MOTO Payments

### Supported alternative payment methods:
* MB PAY

### Google Pay Payments: New Configuration Options

* Button corner radius

This option sets the `border-radius` property of the button and is measured in pixels. There is no need to specify the
CSS `px` unit in this option input field.

### Apple Pay Payments: New Configuration Options

* Button corner radius

This option sets the `border-radius` property of the button and is measured in pixels. There is no need to specify the
CSS `px` unit in this option input field.

* Button height

This option sets the `height` property of the button and is measured in pixels. There is no need to specify the
CSS `px` unit in this option input field.


### Alternative payments: New Configuration Options

* Enable MB WAY Phone Validation
Expand Down
Loading