forked from subscribepro/subscribepro-magento2-adyen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SPRO-54: Display Google Pay & Apple Pay methods via Adyen
Introduce Google and Apple payment methods
- Loading branch information
Dmitry Pryshchepa
committed
Dec 14, 2021
1 parent
ddacc9c
commit 72b98e0
Showing
15 changed files
with
369 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Swarming\SubscribeProAdyen\Model\Ui\Adminhtml; | ||
|
||
use Adyen\Payment\Helper\Data; | ||
use Magento\Framework\View\Element\Template; | ||
use Magento\Vault\Api\Data\PaymentTokenInterface; | ||
use Magento\Vault\Model\Ui\TokenUiComponentInterfaceFactory; | ||
use Magento\Vault\Model\Ui\TokenUiComponentProviderInterface; | ||
|
||
class TokenUiComponentProviderAdyenHpp implements TokenUiComponentProviderInterface | ||
{ | ||
/** | ||
* @var TokenUiComponentInterfaceFactory | ||
*/ | ||
private $componentFactory; | ||
|
||
/** | ||
* @var Data | ||
*/ | ||
private $adyenHelper; | ||
|
||
/** | ||
* TokenUiComponentProvider constructor. | ||
* | ||
* @param TokenUiComponentInterfaceFactory $componentFactory | ||
* @param Data $adyenHelper | ||
*/ | ||
public function __construct( | ||
TokenUiComponentInterfaceFactory $componentFactory, | ||
Data $adyenHelper | ||
) { | ||
$this->componentFactory = $componentFactory; | ||
$this->adyenHelper = $adyenHelper; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getComponentForToken(PaymentTokenInterface $paymentToken) | ||
{ | ||
$details = json_decode($paymentToken->getTokenDetails() ?: '{}', true); | ||
$details['icon'] = $this->adyenHelper->getVariantIcon($details['type']); | ||
$component = $this->componentFactory->create( | ||
[ | ||
'config' => [ | ||
'code' => 'adyen_hpp_vault', | ||
TokenUiComponentProviderInterface::COMPONENT_DETAILS => $details, | ||
TokenUiComponentProviderInterface::COMPONENT_PUBLIC_HASH => $paymentToken->getPublicHash(), | ||
'template' => 'Adyen_Payment::form/vault.phtml' | ||
], | ||
'name' => Template::class | ||
] | ||
); | ||
return $component; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Swarming\SubscribeProAdyen\Model\Ui\Adminhtml; | ||
|
||
use Adyen\Payment\Helper\Data; | ||
use Magento\Framework\View\Element\Template; | ||
use Magento\Vault\Api\Data\PaymentTokenInterface; | ||
use Magento\Vault\Model\Ui\TokenUiComponentInterfaceFactory; | ||
use Magento\Vault\Model\Ui\TokenUiComponentProviderInterface; | ||
|
||
class TokenUiComponentProviderApplePay implements TokenUiComponentProviderInterface | ||
{ | ||
/** | ||
* @var TokenUiComponentInterfaceFactory | ||
*/ | ||
private $componentFactory; | ||
|
||
/** | ||
* @var Data | ||
*/ | ||
private $adyenHelper; | ||
|
||
/** | ||
* TokenUiComponentProvider constructor. | ||
* | ||
* @param TokenUiComponentInterfaceFactory $componentFactory | ||
* @param Data $adyenHelper | ||
*/ | ||
public function __construct( | ||
TokenUiComponentInterfaceFactory $componentFactory, | ||
Data $adyenHelper | ||
) { | ||
$this->componentFactory = $componentFactory; | ||
$this->adyenHelper = $adyenHelper; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getComponentForToken(PaymentTokenInterface $paymentToken) | ||
{ | ||
$details = json_decode($paymentToken->getTokenDetails() ?: '{}', true); | ||
$details['icon'] = $this->adyenHelper->getVariantIcon($details['type']); | ||
$component = $this->componentFactory->create( | ||
[ | ||
'config' => [ | ||
'code' => 'adyen_apple_pay_vault', | ||
TokenUiComponentProviderInterface::COMPONENT_DETAILS => $details, | ||
TokenUiComponentProviderInterface::COMPONENT_PUBLIC_HASH => $paymentToken->getPublicHash(), | ||
'template' => 'Adyen_Payment::form/vault.phtml' | ||
], | ||
'name' => Template::class | ||
] | ||
); | ||
return $component; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Swarming\SubscribeProAdyen\Model\Ui\Adminhtml; | ||
|
||
use Adyen\Payment\Model\Ui\AdyenGooglePayConfigProvider; | ||
use Adyen\Payment\Helper\Data; | ||
use Magento\Framework\View\Element\Template; | ||
use Magento\Vault\Api\Data\PaymentTokenInterface; | ||
use Magento\Vault\Model\Ui\TokenUiComponentInterfaceFactory; | ||
use Magento\Vault\Model\Ui\TokenUiComponentProviderInterface; | ||
|
||
class TokenUiComponentProviderGooglePay implements TokenUiComponentProviderInterface | ||
{ | ||
/** | ||
* @var TokenUiComponentInterfaceFactory | ||
*/ | ||
private $componentFactory; | ||
|
||
/** | ||
* @var Data | ||
*/ | ||
private $adyenHelper; | ||
|
||
/** | ||
* TokenUiComponentProvider constructor. | ||
* | ||
* @param TokenUiComponentInterfaceFactory $componentFactory | ||
* @param Data $adyenHelper | ||
*/ | ||
public function __construct( | ||
TokenUiComponentInterfaceFactory $componentFactory, | ||
Data $adyenHelper | ||
) { | ||
$this->componentFactory = $componentFactory; | ||
$this->adyenHelper = $adyenHelper; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getComponentForToken(PaymentTokenInterface $paymentToken) | ||
{ | ||
$details = json_decode($paymentToken->getTokenDetails() ?: '{}', true); | ||
$details['icon'] = $this->adyenHelper->getVariantIcon($details['type']); | ||
$component = $this->componentFactory->create( | ||
[ | ||
'config' => [ | ||
'code' => AdyenGooglePayConfigProvider::GOOGLE_PAY_VAULT_CODE, | ||
TokenUiComponentProviderInterface::COMPONENT_DETAILS => $details, | ||
TokenUiComponentProviderInterface::COMPONENT_PUBLIC_HASH => $paymentToken->getPublicHash(), | ||
'template' => 'Adyen_Payment::form/vault.phtml' | ||
], | ||
'name' => Template::class | ||
] | ||
); | ||
return $component; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Swarming\SubscribeProAdyen\Observer\Payment; | ||
|
||
use Magento\Vault\Api\Data\PaymentTokenInterface; | ||
use Adyen\Payment\Model\Ui\AdyenHppConfigProvider; | ||
|
||
class AdyenHppTokenAssigner extends TokenAssigner | ||
{ | ||
/** | ||
* @param string $paymentMethodToken | ||
* @param int $customerId | ||
* @return \Magento\Vault\Api\Data\PaymentTokenInterface|null | ||
*/ | ||
protected function getPaymentToken( | ||
string $paymentMethodToken, | ||
int $customerId | ||
): ?PaymentTokenInterface { | ||
return $this->paymentTokenManagement->getByGatewayToken( | ||
$paymentMethodToken, | ||
AdyenHppConfigProvider::CODE, | ||
$customerId | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Swarming\SubscribeProAdyen\Observer\Payment; | ||
|
||
use Magento\Vault\Api\Data\PaymentTokenInterface; | ||
|
||
class ApplePayTokenAssigner extends TokenAssigner | ||
{ | ||
/** | ||
* @param string $paymentMethodToken | ||
* @param int $customerId | ||
* @return \Magento\Vault\Api\Data\PaymentTokenInterface|null | ||
*/ | ||
protected function getPaymentToken( | ||
string $paymentMethodToken, | ||
int $customerId | ||
): ?PaymentTokenInterface { | ||
return $this->paymentTokenManagement->getByGatewayToken( | ||
$paymentMethodToken, | ||
'adyen_apple_pay', | ||
$customerId | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Swarming\SubscribeProAdyen\Observer\Payment; | ||
|
||
use Magento\Vault\Api\Data\PaymentTokenInterface; | ||
|
||
class GooglePayTokenAssigner extends TokenAssigner | ||
{ | ||
/** | ||
* @param string $paymentMethodToken | ||
* @param int $customerId | ||
* @return \Magento\Vault\Api\Data\PaymentTokenInterface|null | ||
*/ | ||
protected function getPaymentToken( | ||
string $paymentMethodToken, | ||
int $customerId | ||
): ?PaymentTokenInterface { | ||
return $this->paymentTokenManagement->getByGatewayToken( | ||
$paymentMethodToken, | ||
'adyen_google_pay', | ||
$customerId | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> | ||
<type name="Magento\Vault\Model\Ui\Adminhtml\TokensConfigProvider"> | ||
<arguments> | ||
<argument name="tokenUiComponentProviders" xsi:type="array"> | ||
<item name="adyen_apple_pay" xsi:type="object">Swarming\SubscribeProAdyen\Model\Ui\Adminhtml\TokenUiComponentProviderApplePay</item> | ||
<item name="adyen_google_pay" xsi:type="object">Swarming\SubscribeProAdyen\Model\Ui\Adminhtml\TokenUiComponentProviderGooglePay</item> | ||
<item name="adyen_hpp" xsi:type="object">Swarming\SubscribeProAdyen\Model\Ui\Adminhtml\TokenUiComponentProviderAdyenHpp</item> | ||
</argument> | ||
</arguments> | ||
</type> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.