Skip to content

Commit e5110e0

Browse files
author
Prabhu Ram
committed
MC-36554: Customer should be able to re-use the payflowPro_cc_vault as payment method for subsequent orders
- Added impl to use vault public hash
1 parent 6cb92ae commit e5110e0

File tree

4 files changed

+102
-2
lines changed

4 files changed

+102
-2
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\PaypalGraphQl\Model\Plugin\Cart\PayflowProCcVault;
9+
10+
use Magento\Quote\Model\Quote;
11+
use Magento\QuoteGraphQl\Model\Cart\Payment\AdditionalDataProviderPool;
12+
use Magento\Sales\Model\Order\Payment\Repository as PaymentRepository;
13+
use Magento\Vault\Api\Data\PaymentTokenInterface;
14+
use Magento\Vault\Api\PaymentTokenManagementInterface;
15+
16+
/**
17+
* Set additionalInformation on payment for PayflowPro vault method
18+
*/
19+
class SetPaymentMethodOnCart
20+
{
21+
const CC_VAULT_CODE = 'payflowpro_cc_vault';
22+
23+
/**
24+
* @var PaymentRepository
25+
*/
26+
private $paymentRepository;
27+
28+
/**
29+
* @var AdditionalDataProviderPool
30+
*/
31+
private $additionalDataProviderPool;
32+
33+
/**
34+
* PaymentTokenManagementInterface $paymentTokenManagement
35+
*/
36+
private $paymentTokenManagement;
37+
38+
/**
39+
* @param PaymentRepository $paymentRepository
40+
* @param AdditionalDataProviderPool $additionalDataProviderPool
41+
* @param PaymentTokenManagementInterface $paymentTokenManagement
42+
*/
43+
public function __construct(
44+
PaymentRepository $paymentRepository,
45+
AdditionalDataProviderPool $additionalDataProviderPool,
46+
PaymentTokenManagementInterface $paymentTokenManagement
47+
) {
48+
$this->paymentRepository = $paymentRepository;
49+
$this->additionalDataProviderPool = $additionalDataProviderPool;
50+
$this->paymentTokenManagement = $paymentTokenManagement;
51+
}
52+
53+
/**
54+
* Set public hash and customer id on payment additionalInformation
55+
*
56+
* @param \Magento\QuoteGraphQl\Model\Cart\SetPaymentMethodOnCart $subject
57+
* @param mixed $result
58+
* @param Quote $cart
59+
* @param array $additionalData
60+
* @return void
61+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
62+
* @throws \Magento\Framework\Exception\LocalizedException
63+
*/
64+
public function afterExecute(
65+
\Magento\QuoteGraphQl\Model\Cart\SetPaymentMethodOnCart $subject,
66+
$result,
67+
Quote $cart,
68+
array $additionalData
69+
): void {
70+
$additionalData = $this->additionalDataProviderPool->getData(self::CC_VAULT_CODE, $additionalData);
71+
$customerId = (int) $cart->getCustomer()->getId();
72+
$payment = $cart->getPayment();
73+
if (!is_array($additionalData) || !isset($additionalData[PaymentTokenInterface::PUBLIC_HASH])) {
74+
return;
75+
}
76+
$tokenPublicHash = $additionalData[PaymentTokenInterface::PUBLIC_HASH];
77+
if ($tokenPublicHash === null) {
78+
return;
79+
}
80+
$paymentToken = $this->paymentTokenManagement->getByPublicHash($tokenPublicHash, $customerId);
81+
if ($paymentToken === null) {
82+
return;
83+
}
84+
$payment->setAdditionalInformation(
85+
[
86+
PaymentTokenInterface::CUSTOMER_ID => $customerId,
87+
PaymentTokenInterface::PUBLIC_HASH => $tokenPublicHash
88+
]
89+
);
90+
$payment->save();
91+
}
92+
}

app/code/Magento/PaypalGraphQl/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"magento/module-quote-graph-ql": "*",
1414
"magento/module-sales": "*",
1515
"magento/module-payment": "*",
16-
"magento/module-store": "*"
16+
"magento/module-store": "*",
17+
"magento/module-vault": "*"
1718
},
1819
"suggest": {
1920
"magento/module-graph-ql": "*",

app/code/Magento/PaypalGraphQl/etc/graphql/di.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<type name="Magento\QuoteGraphQl\Model\Cart\SetPaymentMethodOnCart">
1313
<plugin name="hosted_pro_payment_method" type="Magento\PaypalGraphQl\Model\Plugin\Cart\HostedPro\SetPaymentMethodOnCart"/>
1414
<plugin name="payflowpro_payment_method" type="Magento\PaypalGraphQl\Model\Plugin\Cart\PayflowPro\SetPaymentMethodOnCart"/>
15+
<plugin name="payflowpro_cc_vault_payment_method" type="Magento\PaypalGraphQl\Model\Plugin\Cart\PayflowProCcVault\SetPaymentMethodOnCart"/>
1516
</type>
1617
<type name="Magento\Paypal\Model\Payflowlink">
1718
<plugin name="payflow_link_update_redirect_urls" type="Magento\PaypalGraphQl\Model\Plugin\Payflowlink"/>
@@ -51,6 +52,7 @@
5152
<item name="payflow_advanced" xsi:type="object">Magento\PaypalGraphQl\Model\PayflowLinkAdditionalDataProvider</item>
5253
<item name="payflowpro" xsi:type="object">\Magento\PaypalGraphQl\Model\PayflowProAdditionalDataProvider</item>
5354
<item name="hosted_pro" xsi:type="object">\Magento\PaypalGraphQl\Model\HostedProAdditionalDataProvider</item>
55+
<item name="payflowpro_cc_vault" xsi:type="object">\Magento\PaypalGraphQl\Model\PayflowProCcVaultAdditionalDataProvider</item>
5456
</argument>
5557
</arguments>
5658
</type>

app/code/Magento/PaypalGraphQl/etc/schema.graphqls

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type PayflowLinkToken @doc(description:"Contains information used to generate Pa
3737
paypal_url: String @doc(description:"PayPal URL used for requesting Payflow form")
3838
}
3939

40-
type HostedProUrl @doc(desription:"Contains secure URL used for Payments Pro Hosted Solution payment method.") {
40+
type HostedProUrl @doc(description:"Contains secure URL used for Payments Pro Hosted Solution payment method.") {
4141
secure_form_url: String @doc(description:"Secure Url generated by PayPal")
4242
}
4343

@@ -51,6 +51,7 @@ input PaymentMethodInput {
5151
payflow_link: PayflowLinkInput @doc(description:"Required input for PayPal Payflow Link and Payments Advanced payments")
5252
payflowpro: PayflowProInput @doc(description: "Required input type for PayPal Payflow Pro and Payment Pro payments")
5353
hosted_pro: HostedProInput @doc(description:"Required input for PayPal Hosted pro payments")
54+
payflowpro_cc_vault: VaultTokenInput @doc(description:"Required input type for PayPal Payflow Pro vault payments")
5455
}
5556

5657
input HostedProInput @doc(description:"A set of relative URLs that PayPal will use in response to various actions during the authorization process. Magento prepends the base URL to this value to create a full URL. For example, if the full URL is https://www.example.com/path/to/page.html, the relative URL is path/to/page.html. Use this input for Payments Pro Hosted Solution payment method.") {
@@ -146,3 +147,7 @@ type PayflowProResponseOutput {
146147
type StoreConfig {
147148
payment_payflowpro_cc_vault_active: String @doc(description: "Payflow Pro vault status.")
148149
}
150+
151+
input VaultTokenInput @doc(description:"Required input for payment methods with Vault support.") {
152+
public_hash: String! @doc(description: "The public hash of the payment token")
153+
}

0 commit comments

Comments
 (0)