Skip to content

Commit e9474a2

Browse files
committed
MC-31504: [2.4.0] Update PayPal plugin to use the PayPal JavaScript SDK
- Fixed SmartButtonConfig Test
1 parent 3204d58 commit e9474a2

File tree

6 files changed

+139
-57
lines changed

6 files changed

+139
-57
lines changed

app/code/Magento/Paypal/Model/SmartButtonConfig.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ private function getDisallowedFunding(): array
169169
$result);
170170

171171
//disable unsupported payment methods
172+
$result = array_combine($result, $result);
172173
$result = array_merge($result, $this->unsupportedPaymentMethods);
173174

174175
return $result;

app/code/Magento/Paypal/Test/Unit/Model/SmartButtonConfigTest.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ protected function setUp()
6161
$configFactoryMock,
6262
$scopeConfigMock,
6363
$this->getDefaultStyles(),
64-
$this->getAllowedFundings()
64+
$this->getDisallowedFundingMap(),
65+
$this->getUnsupportedPaymentMethods()
6566
);
6667
}
6768

@@ -73,7 +74,6 @@ protected function setUp()
7374
* @param bool $isCustomize
7475
* @param string $disallowedFundings
7576
* @param string $layout
76-
* @param string $size
7777
* @param string $shape
7878
* @param string $label
7979
* @param string $color
@@ -90,7 +90,6 @@ public function testGetConfig(
9090
bool $isCustomize,
9191
?string $disallowedFundings,
9292
string $layout,
93-
string $size,
9493
string $shape,
9594
string $label,
9695
string $color,
@@ -103,6 +102,7 @@ public function testGetConfig(
103102
$this->configMock->method('getValue')->will(
104103
$this->returnValueMap(
105104
[
105+
['sandbox_client_id', null, 'sb'],
106106
['merchant_id', null, 'merchant'],
107107
[
108108
'solution_type',
@@ -114,7 +114,6 @@ public function testGetConfig(
114114
['disable_funding_options', null, $disallowedFundings],
115115
["{$page}_page_button_customize", null, $isCustomize],
116116
["{$page}_page_button_layout", null, $layout],
117-
["{$page}_page_button_size", null, $size],
118117
["{$page}_page_button_color", null, $color],
119118
["{$page}_page_button_shape", null, $shape],
120119
["{$page}_page_button_label", null, $label],
@@ -151,12 +150,23 @@ private function getDefaultStyles()
151150
}
152151

153152
/**
154-
* Get allowed fundings
153+
* Get disallowed funding map
155154
*
156155
* @return array
157156
*/
158-
private function getAllowedFundings()
157+
private function getDisallowedFundingMap()
159158
{
160-
return include __DIR__ . '/_files/allowed_fundings.php';
159+
return include __DIR__ . '/_files/disallowed_funding_map.php';
161160
}
161+
162+
/**
163+
* Get unsupported payment methods
164+
*
165+
* @return array
166+
*/
167+
private function getUnsupportedPaymentMethods()
168+
{
169+
return include __DIR__ . '/_files/unsupported_payment_methods.php';
170+
}
171+
162172
}

app/code/Magento/Paypal/Test/Unit/Model/_files/allowed_fundings.php

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
/**
7+
* Copyright © Magento, Inc. All rights reserved.
8+
* See COPYING.txt for license details.
9+
*/
10+
declare(strict_types=1);
11+
12+
return [
13+
"CREDIT" => 'credit',
14+
"CARD" => 'card',
15+
"ELV" => 'sepa'
16+
];

app/code/Magento/Paypal/Test/Unit/Model/_files/expected_config.php

Lines changed: 88 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,24 @@
55
*/
66
declare(strict_types=1);
77

8+
/**
9+
* Generates expected PayPal SDK url
10+
* @param array $params
11+
* @return String
12+
*/
13+
function generateExpectedPaypalSdkUrl(array $params) : String
14+
{
15+
return 'https://www.paypal.com/sdk/js?' . http_build_query($params);
16+
}
17+
818
return [
919
'cart' => [
1020
'cart',
1121
'es_MX',
1222
true,
1323
'CREDIT',
1424
'horizontal',
15-
'small',
16-
'pillow',
25+
'pill',
1726
'installment',
1827
'blue',
1928
'my_label',
@@ -22,16 +31,27 @@
2231
[
2332
'styles' => [
2433
'layout' => 'horizontal',
25-
'size' => 'small',
34+
'size' => null,
2635
'color' => 'blue',
27-
'shape' => 'pillow',
36+
'shape' => 'pill',
2837
'label' => 'installment',
2938
'period' => 0
3039
],
3140
'isVisibleOnProductPage' => false,
3241
'isGuestCheckoutAllowed' => true,
33-
'sdkUrl' => 'https://www.paypal.com/sdk/js?commit=false&merchant-id=merchant&locale=es_MX&' .
34-
'intent=authorize&disable-funding=CREDIT'
42+
'sdkUrl' => generateExpectedPaypalSdkUrl(
43+
[
44+
'client-id' => 'sb',
45+
'commit' => 'false',
46+
'merchant-id' => 'merchant',
47+
'locale' => 'es_MX',
48+
'intent' => 'authorize',
49+
'disable-funding' => implode(
50+
',',
51+
['credit', 'venmo', 'bancontact', 'eps', 'giropay', 'ideal', 'mybank', 'p24', 'sofort']
52+
)
53+
]
54+
)
3555
]
3656
],
3757
'checkout' => [
@@ -40,8 +60,7 @@
4060
true,
4161
null,
4262
'horizontal',
43-
'small',
44-
'pillow',
63+
'pill',
4564
'installment',
4665
'blue',
4766
'my_label',
@@ -50,25 +69,36 @@
5069
[
5170
'styles' => [
5271
'layout' => 'horizontal',
53-
'size' => 'small',
72+
'size' => null,
5473
'color' => 'blue',
55-
'shape' => 'pillow',
74+
'shape' => 'pill',
5675
'label' => 'installment',
5776
'period' => 0
5877
],
5978
'isVisibleOnProductPage' => false,
6079
'isGuestCheckoutAllowed' => true,
61-
'sdkUrl' => 'https://www.paypal.com/sdk/js?commit=false&merchant-id=merchant&locale=en_BR&intent=authorize'
80+
'sdkUrl' => generateExpectedPaypalSdkUrl(
81+
[
82+
'client-id' => 'sb',
83+
'commit' => 'false',
84+
'merchant-id' => 'merchant',
85+
'locale' => 'en_BR',
86+
'intent' => 'authorize',
87+
'disable-funding' => implode(
88+
',',
89+
['venmo', 'bancontact', 'eps', 'giropay', 'ideal', 'mybank', 'p24', 'sofort']
90+
)
91+
]
92+
)
6293
]
6394
],
6495
'mini_cart' => [
6596
'cart',
66-
'en',
97+
'en_US',
6798
false,
6899
null,
69100
'horizontal',
70-
'small',
71-
'pillow',
101+
'pill',
72102
'installment',
73103
'blue',
74104
'my_label',
@@ -84,17 +114,28 @@
84114
],
85115
'isVisibleOnProductPage' => false,
86116
'isGuestCheckoutAllowed' => true,
87-
'sdkUrl' => 'https://www.paypal.com/sdk/js?commit=false&merchant-id=merchant&locale=en&intent=authorize'
117+
'sdkUrl' => generateExpectedPaypalSdkUrl(
118+
[
119+
'client-id' => 'sb',
120+
'commit' => 'false',
121+
'merchant-id' => 'merchant',
122+
'locale' => 'en_US',
123+
'intent' => 'authorize',
124+
'disable-funding' => implode(
125+
',',
126+
['venmo', 'bancontact', 'eps', 'giropay', 'ideal', 'mybank', 'p24', 'sofort']
127+
)
128+
]
129+
)
88130
]
89131
],
90132
'product' => [
91133
'cart',
92-
'en',
134+
'en_US',
93135
false,
94136
'CREDIT',
95137
'horizontal',
96-
'small',
97-
'pillow',
138+
'pill',
98139
'installment',
99140
'blue',
100141
'my_label',
@@ -110,8 +151,19 @@
110151
],
111152
'isVisibleOnProductPage' => false,
112153
'isGuestCheckoutAllowed' => true,
113-
'sdkUrl' => 'https://www.paypal.com/sdk/js?commit=false&merchant-id=merchant&locale=en&intent=authorize'
114-
. '&disable-funding=CREDIT'
154+
'sdkUrl' => generateExpectedPaypalSdkUrl(
155+
[
156+
'client-id' => 'sb',
157+
'commit' => 'false',
158+
'merchant-id' => 'merchant',
159+
'locale' => 'en_US',
160+
'intent' => 'authorize',
161+
'disable-funding' => implode(
162+
',',
163+
['credit','venmo', 'bancontact', 'eps', 'giropay', 'ideal', 'mybank', 'p24', 'sofort']
164+
)
165+
]
166+
)
115167
]
116168
],
117169
'checkout_with_paypal_guest_checkout_disabled' => [
@@ -120,8 +172,7 @@
120172
true,
121173
null,
122174
'horizontal',
123-
'small',
124-
'pillow',
175+
'pill',
125176
'installment',
126177
'blue',
127178
'my_label',
@@ -130,16 +181,27 @@
130181
[
131182
'styles' => [
132183
'layout' => 'horizontal',
133-
'size' => 'small',
184+
'size' => null,
134185
'color' => 'blue',
135-
'shape' => 'pillow',
186+
'shape' => 'pill',
136187
'label' => 'installment',
137188
'period' => 0
138189
],
139190
'isVisibleOnProductPage' => false,
140191
'isGuestCheckoutAllowed' => true,
141-
'sdkUrl' => 'https://www.paypal.com/sdk/js?commit=false&merchant-id=merchant&locale=en_BR'
142-
. '&intent=authorize&disable-funding=CARD'
192+
'sdkUrl' => generateExpectedPaypalSdkUrl(
193+
[
194+
'client-id' => 'sb',
195+
'commit' => 'false',
196+
'merchant-id' => 'merchant',
197+
'locale' => 'en_BR',
198+
'intent' => 'authorize',
199+
'disable-funding' => implode(
200+
',',
201+
['card','venmo', 'bancontact', 'eps', 'giropay', 'ideal', 'mybank', 'p24', 'sofort']
202+
)
203+
]
204+
)
143205
]
144206
],
145207
];
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
return [
9+
'venmo'=> 'venmo',
10+
'bancontact' => 'bancontact',
11+
'eps' => 'eps',
12+
'giropay' => 'giropay',
13+
'ideal' => 'ideal',
14+
'mybank' => 'mybank',
15+
'p24' => 'p24',
16+
'sofort' => 'sofort'
17+
];

0 commit comments

Comments
 (0)