Skip to content
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
17 changes: 2 additions & 15 deletions Block/Vault/CardRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@

use Magento\Vault\Api\Data\PaymentTokenInterface;
use Magento\Vault\Block\AbstractCardRenderer;
use Swarming\SubscribePro\Gateway\Config\ApplePayConfigProvider;
use Swarming\SubscribePro\Gateway\Config\ConfigProvider;
use Swarming\SubscribePro\Helper\Vault as VaultHelper;

class CardRenderer extends AbstractCardRenderer
{
/**
* @param \Magento\Vault\Api\Data\PaymentTokenInterface $token
* @return boolean
* @return bool
*/
public function canRender(PaymentTokenInterface $token)
{
return ($token->getPaymentMethodCode() === ConfigProvider::CODE);
return $token->getPaymentMethodCode() === ConfigProvider::CODE;
}

/**
Expand Down Expand Up @@ -67,16 +66,4 @@ public function isPending()
$state = $this->getTokenDetails()['state'] ?? null;
return $state === VaultHelper::STATE_PENDING;
}

/**
* @return string
*/
public function getApplePayLabel()
{
$label = '';
if ($this->getToken()->getPaymentMethodCode() === ApplePayConfigProvider::CODE) {
$label = '(' . __('ApplePay') . ')';
}
return $label;
}
}
11 changes: 10 additions & 1 deletion Model/Quote/Payment/GetPaymentProfileId.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use SubscribePro\Service\Address\AddressInterface;
use SubscribePro\Service\PaymentProfile\PaymentProfileInterface;
use Swarming\SubscribePro\Gateway\Config\ConfigProvider as SubscribeProConfigProvider;
use Swarming\SubscribePro\Gateway\Config\ApplePayConfigProvider;

class GetPaymentProfileId
{
Expand All @@ -28,6 +29,14 @@ class GetPaymentProfileId
*/
private $paymentProfileDataBuilder;

/**
* @var string[]
*/
private $sproPaymentMethods = [
SubscribeProConfigProvider::CODE,
ApplePayConfigProvider::CODE
];

/**
* @param \Magento\Vault\Api\PaymentTokenManagementInterface $tokenManagement
* @param \Swarming\SubscribePro\Platform\Service\PaymentProfile $platformPaymentProfileService
Expand Down Expand Up @@ -56,7 +65,7 @@ public function execute(OrderPaymentInterface $payment, int $platformCustomerId)
throw new \UnexpectedValueException('The vault is not found.');
}

return $paymentToken->getPaymentMethodCode() === SubscribeProConfigProvider::CODE
return in_array($paymentToken->getPaymentMethodCode(), $this->sproPaymentMethods, true)
? $paymentToken->getGatewayToken()
: $this->getExternalProfileId($paymentToken, $payment->getOrder(), $platformCustomerId);
}
Expand Down
41 changes: 34 additions & 7 deletions Observer/Payment/TokenAssigner.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<?php

declare(strict_types=1);

namespace Swarming\SubscribePro\Observer\Payment;

use Magento\Framework\Event\Observer;
use Magento\Quote\Api\Data\PaymentInterface;
use Magento\Quote\Model\Quote\Payment as QuotePayment;
use Magento\Vault\Api\Data\PaymentTokenInterface;
use SubscribePro\Service\Transaction\TransactionInterface;
use Swarming\SubscribePro\Gateway\Request\VaultDataBuilder;
use Swarming\SubscribePro\Gateway\Config\ConfigProvider;
use Magento\Quote\Model\Quote\Payment as QuotePayment;
use Swarming\SubscribePro\Gateway\Config\ApplePayConfigProvider;
use SubscribePro\Service\Transaction\TransactionInterface;

class TokenAssigner extends \Magento\Payment\Observer\AbstractDataAssignObserver
{
Expand Down Expand Up @@ -36,12 +38,11 @@ public function execute(Observer $observer)

$additionalData = $dataObject->getData(PaymentInterface::KEY_ADDITIONAL_DATA);

if (!is_array($additionalData) || !isset($additionalData[VaultDataBuilder::PAYMENT_PROFILE_ID])) {
$paymentProfileId = $additionalData['profile_id'] ?? null;
if (empty($paymentProfileId)) {
return;
}

$profileId = $additionalData[VaultDataBuilder::PAYMENT_PROFILE_ID];

/** @var \Magento\Quote\Model\Quote\Payment $paymentModel */
$paymentModel = $this->readPaymentModelArgument($observer);
if (!$paymentModel instanceof QuotePayment) {
Expand All @@ -54,7 +55,11 @@ public function execute(Observer $observer)
return;
}

$paymentToken = $this->paymentTokenManagement->getByGatewayToken($profileId, ConfigProvider::CODE, $customerId);
$paymentToken = $this->paymentTokenManagement->getByGatewayToken(
$paymentProfileId,
$this->getPaymentMethodCode($additionalData),
$customerId
);
if ($paymentToken === null) {
return;
}
Expand All @@ -76,4 +81,26 @@ public function execute(Observer $observer)
);
}
}

/**
* @param array $additionalData
* @return string
*/
private function getPaymentMethodCode(array $additionalData): string
{
$paymentMethodType = $additionalData['payment_method_type'] ?? '';

switch ($paymentMethodType) {
case 'apple_pay':
$paymentMethodCode = ApplePayConfigProvider::CODE;
break;
case 'credit_card':
default:
$paymentMethodCode = ConfigProvider::CODE;
break;

}

return $paymentMethodCode;
}
}
3 changes: 2 additions & 1 deletion Service/OrderCallback/DataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ public function importPaymentData(
$quotePayment->setMethod($paymentMethodVault);
$quotePayment->getMethodInstance();

$paymentAdditionalData['payment_method_type'] = $this->getValue($paymentData, 'paymentMethodType');
$paymentAdditionalData['profile_id'] = $this->getValue($paymentData, 'paymentProfileId');
$paymentAdditionalData['cc_type'] = $this->getValue($paymentData, 'creditcardType');
$paymentAdditionalData['cc_number'] = $this->getValue($paymentData, 'creditcardLastDigits');
Expand Down Expand Up @@ -180,7 +181,7 @@ private function getPaymentTokenObject(

$paymentToken = null;
foreach ($allowedPaymentCodes as $paymentCode) {
/** @var Magento\Vault\Api\Data\PaymentTokenInterface $paymentToken */
/** @var \Magento\Vault\Api\Data\PaymentTokenInterface $paymentToken */
$paymentToken = $this->paymentTokenManagement->getByGatewayToken(
$paymentTokenValue,
$paymentCode,
Expand Down
9 changes: 2 additions & 7 deletions etc/di.xml
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -543,17 +543,12 @@
<argument name="logger" xsi:type="object">Swarming\SubscribePro\Model\VirtualLogger</argument>
</arguments>
</type>
<type name="Swarming\SubscribePro\Model\ApplePay\PaymentAuthorized">
<type name="Swarming\SubscribePro\Controller\Applepay\ShippingMethod">
<arguments>
<argument name="logger" xsi:type="object">Swarming\SubscribePro\Model\VirtualLogger</argument>
</arguments>
</type>
<type name="Swarming\SubscribePro\Controller\ApplePay\Shipping">
<arguments>
<argument name="logger" xsi:type="object">Swarming\SubscribePro\Model\VirtualLogger</argument>
</arguments>
</type>
<type name="Swarming\SubscribePro\Controller\ApplePay\ShippingList">
<type name="Swarming\SubscribePro\Controller\Applepay\ShippingList">
<arguments>
<argument name="logger" xsi:type="object">Swarming\SubscribePro\Model\VirtualLogger</argument>
</arguments>
Expand Down
1 change: 0 additions & 1 deletion view/frontend/templates/vault/card_render.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ $ccNumberView = $block->escapeHtml($block->getNumberLast4Digits());
<?php if ($block->isPending()): ?>
<sub class="card-pending"><?= $block->escapeHtml(__('pending')) ?></sub>
<?php endif; ?>
<?= $block->escapeHtml($block->getApplePayLabel()) ?>
</td>
<td data-th="<?= $block->escapeHtml(__('Expiration Date')) ?>" class="col card-expire">
<?= $block->escapeHtml($block->getExpDate()) ?>
Expand Down