Skip to content

Commit c3fa84a

Browse files
committed
Merge remote-tracking branch 'origin/AC2093' into gl_pr_arrows_paypal_april21_2022
2 parents b317072 + 4659f2d commit c3fa84a

File tree

7 files changed

+74
-5
lines changed

7 files changed

+74
-5
lines changed

app/code/Magento/Paypal/Controller/Express/OnAuthorization.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,19 @@
3333
class OnAuthorization extends AbstractExpress implements HttpPostActionInterface
3434
{
3535
/**
36+
* @var PayPalConfig
3637
* @inheritdoc
3738
*/
3839
protected $_configType = PayPalConfig::class;
3940

4041
/**
42+
* @var PayPalConfig
4143
* @inheritdoc
4244
*/
4345
protected $_configMethod = PayPalConfig::METHOD_WPP_EXPRESS;
4446

4547
/**
48+
* @var PayPalCheckout
4649
* @inheritdoc
4750
*/
4851
protected $_checkoutType = PayPalCheckout::class;
@@ -53,8 +56,6 @@ class OnAuthorization extends AbstractExpress implements HttpPostActionInterface
5356
private $cartRepository;
5457

5558
/**
56-
* Url Builder
57-
*
5859
* @var UrlInterface
5960
*/
6061
private $urlBuilder;
@@ -116,6 +117,7 @@ public function execute(): ResultInterface
116117
$controllerResult = $this->resultFactory->create(ResultFactory::TYPE_JSON);
117118
$payerId = $this->getRequest()->getParam('payerId');
118119
$tokenId = $this->getRequest()->getParam('paymentToken');
120+
$fundingSource = $this->getRequest()->getParam('paypalFundingSource');
119121

120122
try {
121123
$quote = $this->_getQuote();
@@ -127,6 +129,7 @@ public function execute(): ResultInterface
127129

128130
/** Populate checkout object with new data */
129131
$this->_initCheckout($quote);
132+
$quote->getPayment()->setAdditionalInformation(PayPalCheckout::PAYMENT_INFO_FUNDING_SOURCE, $fundingSource);
130133
/** Populate quote with information about billing and shipping addresses*/
131134
$this->_checkout->returnFromPaypal($tokenId, $payerId);
132135
if ($this->_checkout->canSkipOrderReviewStep()) {

app/code/Magento/Paypal/Model/Express/Checkout.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class Checkout
4242
public const PAYMENT_INFO_TRANSPORT_PAYER_ID = 'paypal_express_checkout_payer_id';
4343
public const PAYMENT_INFO_TRANSPORT_REDIRECT = 'paypal_express_checkout_redirect_required';
4444
public const PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT = 'paypal_ec_create_ba';
45+
public const PAYMENT_INFO_FUNDING_SOURCE = 'paypal_funding_source';
4546

4647
/**
4748
* Flag which says that was used PayPal Express Checkout button for checkout
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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\Paypal\ViewModel;
9+
10+
use Magento\Checkout\Model\Session;
11+
use Magento\Framework\View\Element\Block\ArgumentInterface;
12+
use Magento\Paypal\Model\Express\Checkout;
13+
14+
/**
15+
* Provides Paypal funding source data
16+
*
17+
*/
18+
class PaypalFundingSourceDataProvider implements ArgumentInterface
19+
{
20+
/**
21+
* @var Session
22+
*/
23+
private $checkoutSession;
24+
25+
/**
26+
* @param Session $checkoutSession
27+
*/
28+
public function __construct(
29+
Session $checkoutSession
30+
) {
31+
$this->checkoutSession = $checkoutSession;
32+
}
33+
34+
/**
35+
* Return paypal funding source
36+
*
37+
* @return string|null
38+
*/
39+
public function getPaypalFundingSource()
40+
{
41+
$quote = $this->checkoutSession->getQuote();
42+
if ($quote->getPayment()->getAdditionalInformation(Checkout::PAYMENT_INFO_FUNDING_SOURCE)) {
43+
return ucfirst($quote->getPayment()->getAdditionalInformation(
44+
Checkout::PAYMENT_INFO_FUNDING_SOURCE
45+
));
46+
}
47+
return null;
48+
}
49+
}

app/code/Magento/Paypal/view/frontend/layout/paypal_express_review.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
</referenceContainer>
2121
<referenceContainer name="content">
2222
<block class="Magento\Paypal\Block\Express\Review" name="paypal.express.review" template="Magento_Paypal::express/review.phtml">
23+
<arguments>
24+
<argument name="PaypalFundingSourceDataProvider" xsi:type="object">Magento\Paypal\ViewModel\PaypalFundingSourceDataProvider</argument>
25+
</arguments>
2326
<block class="Magento\Paypal\Block\Express\Review" name="express.review.shipping.method" as="shipping_method" template="Magento_Paypal::express/review/shipping/method.phtml"/>
2427
<block class="Magento\Framework\View\Element\Text\ListText" name="paypal.additional.actions">
2528
<block class="Magento\Checkout\Block\Cart\Coupon" name="paypal.cart.coupon" as="coupon" template="Magento_Checkout::cart/coupon.phtml"/>

app/code/Magento/Paypal/view/frontend/layout/paypal_payflowexpress_review.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
</referenceContainer>
2121
<referenceContainer name="content">
2222
<block class="Magento\Paypal\Block\Express\Review" name="paypal.express.review" template="Magento_Paypal::express/review.phtml">
23+
<arguments>
24+
<argument name="PaypalFundingSourceDataProvider" xsi:type="object">Magento\Paypal\ViewModel\PaypalFundingSourceDataProvider</argument>
25+
</arguments>
2326
<action method="setControllerPath">
2427
<argument name="prefix" xsi:type="string">paypal/payflowexpress</argument>
2528
</action>

app/code/Magento/Paypal/view/frontend/templates/express/review.phtml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ use Magento\Paypal\Block\Express\Review;
1313
* @var Escaper $escaper
1414
* @var SecureHtmlRenderer $secureRenderer
1515
*/
16+
17+
/** @var \Magento\Paypal\ViewModel\PaypalFundingSourceDataProvider $paypalFundingSourceDataProvider */
18+
$paypalFundingSourceDataProvider = $block->getData('PaypalFundingSourceDataProvider');
1619
?>
1720
<div class="paypal-review view">
1821
<div class="block block-order-details-view">
@@ -101,7 +104,8 @@ use Magento\Paypal\Block\Express\Review;
101104
<div class="box box-order-billing-address">
102105
<strong class="box-title"><span><?= $escaper->escapeHtml(__('Payment Method')) ?></span></strong>
103106
<div class="box-content">
104-
<?= $escaper->escapeHtml($block->getPaymentMethodTitle()) ?><br>
107+
<?= $escaper->escapeHtml($paypalFundingSourceDataProvider->getPaypalFundingSource()
108+
?? $block->getPaymentMethodTitle()) ?><br>
105109
<?= $escaper->escapeHtml($block->getEmail()) ?> <br>
106110
<img src="https://www.paypalobjects.com/webstatic/en_US/i/buttons/pp-acceptance-medium.png"
107111
alt="<?= $block->escapeHtml(__('Buy now with PayPal')) ?>"/>
@@ -150,6 +154,7 @@ use Magento\Paypal\Block\Express\Review;
150154
</form>
151155
</div>
152156
</div>
157+
<?php // phpcs:ignore Magento2.Legacy.PhtmlTemplate ?>
153158
<script type="text/x-magento-init">
154159
{
155160
"#order-review-form": {

app/code/Magento/Paypal/view/frontend/web/js/in-context/express-checkout-smart-buttons.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ define([
77
'underscore',
88
'jquery',
99
'Magento_Paypal/js/in-context/paypal-sdk',
10+
'Magento_Customer/js/customer-data',
1011
'domReady!'
11-
], function (_, $, paypalSdk) {
12+
], function (_, $, paypalSdk, customerData) {
1213
'use strict';
1314

1415
/**
@@ -47,6 +48,7 @@ define([
4748
var params = {
4849
paymentToken: data.orderID,
4950
payerId: data.payerID,
51+
paypalFundingSource: customerData.get('paypal-funding-source'),
5052
'form_key': clientConfig.formKey
5153
};
5254

@@ -56,8 +58,10 @@ define([
5658
$.post(clientConfig.onAuthorizeUrl, params).done(function (res) {
5759
clientConfig.rendererComponent
5860
.afterOnAuthorize(res, deferred.resolve, deferred.reject, actions);
61+
customerData.set('paypal-funding-source', '');
5962
}).fail(function (jqXHR, textStatus, err) {
6063
clientConfig.rendererComponent.catchOnAuthorize(err, deferred.resolve, deferred.reject);
64+
customerData.set('paypal-funding-source', '');
6165
});
6266
});
6367
}).promise();
@@ -97,7 +101,8 @@ define([
97101
/**
98102
* Execute logic on Paypal button click
99103
*/
100-
onClick: function () {
104+
onClick: function (data) {
105+
customerData.set('paypal-funding-source', data.fundingSource);
101106
clientConfig.rendererComponent.validate();
102107
clientConfig.rendererComponent.onClick();
103108
},

0 commit comments

Comments
 (0)