Skip to content

Commit 724eb0f

Browse files
L3RAZMatt75GytisZuminvertus-jscGytautas Zumaras
authored
BNPL + VENMO + PUI (#1453)
* [PAYSHIP-3554] BNPL Configurator / Adds new PayLater configuration handling (#1388) * Added new PayLater configuration handling and removed old configuration references * Apply PHP-CS-Fixer changes * Code review feedback * Apply PHP-CS-Fixer changes * Fixed default config * Removed hardcoded country for debugging * changed the way json config is handled * Bumped muodle version * Bump module version * Remove useless import * Improve the PayPalPayLaterConfiguration * Added validation for merchant country/locale/currency * Apply PHP-CS-Fixer changes * Updated default configuration to enable messages * Fixed upgrade file config name --------- Co-authored-by: L3RAZ <L3RAZ@users.noreply.github.com> Co-authored-by: Matt75 <5262628+Matt75@users.noreply.github.com> * Venmo payment method implementation (#1433) * Added venmo to funding source repository * Added venmo payment source building * Changed the way US state names are handled in shipping node * Modified Payment node builder * injection fix * Fixed full name on shipping node * Removed gender from shipping address full_name property * Bumbed module version --------- Co-authored-by: Invertus <developers@invertus.eu> Co-authored-by: Gytautas Zumaras <gytautaszumaras@Mac.localdomain> * Pay Upon Invoice implementation (#1432) * feat: PUI implementations for rendering and payload corrections * feat: PUI order creation logic improved * fix: fix validation by adding correct status * Apply PHP-CS-Fixer changes * birthday autofill for ps17 and ps9 * fix translations for pui * fix upgrades * bump version * add error message for pay upon invoice available range * Do not display Ratepay logo * Update DE translations * Apply PHP-CS-Fixer changes * Update DE translations - 2 --------- Co-authored-by: Gytautas Zumaras <gytautaszumaras@Mac.localdomain> Co-authored-by: GytisZum <GytisZum@users.noreply.github.com> Co-authored-by: Gytautas Zumaras <gytautaszumaras@Gytautass-MacBook-Pro.local> Co-authored-by: Mathieu Ferment <mathieu.ferment@prestashop.com> Co-authored-by: matks <matks@users.noreply.github.com> * Apply PHP-CS-Fixer changes * Removed testing funding source * Added Pay upon Invoice translation * Made PUI and venmo disabled by default --------- Co-authored-by: L3RAZ <L3RAZ@users.noreply.github.com> Co-authored-by: Matt75 <5262628+Matt75@users.noreply.github.com> Co-authored-by: Gytautas Zumaras <96050852+GytisZum@users.noreply.github.com> Co-authored-by: Invertus <developers@invertus.eu> Co-authored-by: Gytautas Zumaras <gytautaszumaras@Mac.localdomain> Co-authored-by: GytisZum <GytisZum@users.noreply.github.com> Co-authored-by: Gytautas Zumaras <gytautaszumaras@Gytautass-MacBook-Pro.local> Co-authored-by: Mathieu Ferment <mathieu.ferment@prestashop.com> Co-authored-by: matks <matks@users.noreply.github.com>
1 parent a691633 commit 724eb0f

File tree

96 files changed

+2284
-270
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+2284
-270
lines changed

api/src/Http/Exception/PayPalException.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,4 +345,6 @@ class PayPalException extends PsCheckoutException
345345
const CREDIT_CARD_NUMBER_IS_INVALID = 160;
346346

347347
const CARD_EXPIRATION_YEAR_IS_INVALID = 161;
348+
349+
const ORDER_REQUIRES_ASYNC_CAPTURE = 162;
348350
}

api/src/Http/OrderHttpClient.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ public function sendRequest(RequestInterface $request): ResponseInterface
5757
/**
5858
* {@inheritdoc}
5959
*/
60-
public function createOrder(array $payload): ResponseInterface
60+
public function createOrder(array $payload, array $headers = []): ResponseInterface
6161
{
62-
return $this->sendRequest(new Request('POST', '/payments/order/create', [], json_encode($payload)));
62+
return $this->sendRequest(new Request('POST', '/payments/order/create', $headers, json_encode($payload)));
6363
}
6464

6565
/**

api/src/Http/OrderHttpClientInterface.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ interface OrderHttpClientInterface
3131
{
3232
/**
3333
* @param array $payload
34+
* @param array $headers
3435
*
3536
* @return ResponseInterface
3637
*
3738
* @throws NetworkException|HttpException|RequestException|TransferException|PayPalException
3839
*/
39-
public function createOrder(array $payload): ResponseInterface;
40+
public function createOrder(array $payload, array $headers = []): ResponseInterface;
4041

4142
/**
4243
* @param array $payload

core/src/FundingSource/Constraint/FundingSourceConstraint.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ public static function getCountries(string $fundingSourceName): array
3838
'ideal' => ['NL'],
3939
'mybank' => ['IT'],
4040
'p24' => ['PL'],
41-
'paylater' => ['FR', 'GB', 'US', 'ES', 'IT'],
41+
'paylater' => ['AU', 'DE', 'ES', 'FR', 'GB', 'IT', 'US'],
4242
'google_pay' => ['AU', 'AT', 'BE', 'BG', 'CA', 'CN', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GR', 'HK', 'HU', 'IE', 'IT', 'JP', 'LV', 'LI', 'LT', 'LU', 'MT', 'NL', 'NO', 'PL', 'PT', 'RO', 'SG', 'SK', 'SI', 'ES', 'SE', 'GB', 'US'],
4343
'apple_pay' => ['AU', 'AT', 'BE', 'BG', 'CA', 'CN', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GR', 'HK', 'HU', 'IE', 'IT', 'JP', 'LV', 'LI', 'LT', 'LU', 'MT', 'NL', 'NO', 'PL', 'PT', 'RO', 'SG', 'SK', 'SI', 'ES', 'SE', 'GB', 'US'],
44+
'venmo' => ['US'],
45+
'pay_upon_invoice' => ['DE'],
4446
];
4547

4648
return isset($countries[$fundingSourceName]) ? $countries[$fundingSourceName] : [];
@@ -58,6 +60,9 @@ public static function getCurrencies(string $fundingSourceName): array
5860
$currencies = [
5961
'google_pay' => ['AUD', 'BRL', 'CAD', 'CHF', 'CZK', 'DKK', 'EUR', 'GBP', 'HKD', 'HUF', 'ILS', 'JPY', 'MXN', 'NOK', 'NZD', 'PHP', 'PLN', 'SEK', 'SGD', 'THB', 'TWD', 'USD'],
6062
'apple_pay' => ['AUD', 'BRL', 'CAD', 'CHF', 'CZK', 'DKK', 'EUR', 'GBP', 'HKD', 'HUF', 'ILS', 'JPY', 'MXN', 'NOK', 'NZD', 'PHP', 'PLN', 'SEK', 'SGD', 'THB', 'TWD', 'USD'],
63+
'paylater' => ['EUR', 'USD', 'AUD', 'GBP'],
64+
'venmo' => ['USD'],
65+
'pay_upon_invoice' => ['EUR'],
6166
];
6267

6368
return isset($currencies[$fundingSourceName]) ? $currencies[$fundingSourceName] : [];

core/src/Order/Builder/Node/AmountBreakdownNode.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ class AmountBreakdownNode implements AmountBreakdownNodeInterface
3030
*/
3131
private $cart;
3232

33+
/**
34+
* @var string|null
35+
*/
36+
private $fundingSource;
37+
3338
/**
3439
* {@inheritDoc}
3540
*/
@@ -69,6 +74,10 @@ public function build(): array
6974
$paypalItem['quantity'] = $quantity;
7075
$paypalItem['category'] = $value['is_virtual'] === '1' ? 'DIGITAL_GOODS' : 'PHYSICAL_GOODS';
7176

77+
if ($this->fundingSource === 'pay_upon_invoice' && isset($value['rate'])) {
78+
$paypalItem['tax_rate'] = NumberUtility::formatAmount($value['rate'], $currencyIsoCode);
79+
}
80+
7281
$node['items'][] = $paypalItem;
7382
}
7483

@@ -131,4 +140,18 @@ public function setCart(array $cart): self
131140

132141
return $this;
133142
}
143+
144+
/**
145+
* Set the funding source to determine if tax_rate is required
146+
*
147+
* @param string|null $fundingSource
148+
*
149+
* @return $this
150+
*/
151+
public function setFundingSource($fundingSource): self
152+
{
153+
$this->fundingSource = $fundingSource;
154+
155+
return $this;
156+
}
134157
}

core/src/Order/Builder/Node/CardPaymentSourceNodeBuilder.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ public function build(): array
8080
$address = $this->cart['addresses']['invoice'];
8181

8282
$countryIso = $this->countryRepository->getCountryIsoCodeById($address->id_country);
83-
$stateName = $this->stateRepository->getNameById($address->id_state);
83+
$stateName = $countryIso === 'US' ?
84+
$this->stateRepository->getIsoById($address->id_state)
85+
: $this->stateRepository->getNameById($address->id_state);
8486

8587
$node = [
8688
'payment_source' => [

core/src/Order/Builder/Node/PayerNodeBuilder.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ public function build()
8686
? $this->countryRepository->getCountryIsoCodeById($invoiceAddress->id_country)
8787
: '';
8888

89+
if (isset($invoiceAddress->id_state)) {
90+
$stateName = $payerCountryIsoCode === 'US' ?
91+
$this->stateRepository->getIsoById($invoiceAddress->id_state)
92+
: $this->stateRepository->getNameById($invoiceAddress->id_state);
93+
} else {
94+
$stateName = '';
95+
}
96+
8997
$node['payer'] = [
9098
'name' => [
9199
'given_name' => isset($invoiceAddress->firstname) ? (string) $invoiceAddress->firstname : '',
@@ -94,7 +102,7 @@ public function build()
94102
'address' => OrderPayloadUtility::getAddressPortable(
95103
$invoiceAddress,
96104
$payerCountryIsoCode,
97-
isset($invoiceAddress->id_state) ? $this->stateRepository->getNameById($invoiceAddress->id_state) : ''
105+
$stateName
98106
),
99107
];
100108

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<?php
2+
/**
3+
* Copyright since 2007 PrestaShop SA and Contributors
4+
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
5+
*
6+
* NOTICE OF LICENSE
7+
*
8+
* This source file is subject to the Academic Free License version 3.0
9+
* that is bundled with this package in the file LICENSE.md.
10+
* It is also available through the world-wide-web at this URL:
11+
* https://opensource.org/licenses/AFL-3.0
12+
* If you did not receive a copy of the license and are unable to
13+
* obtain it through the world-wide-web, please send an email
14+
* to license@prestashop.com so we can send you a copy immediately.
15+
*
16+
* @author PrestaShop SA and Contributors <contact@prestashop.com>
17+
* @copyright Since 2007 PrestaShop SA and Contributors
18+
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
19+
*/
20+
21+
namespace PsCheckout\Core\Order\Builder\Node\PaymentSource;
22+
23+
use PsCheckout\Core\Settings\Configuration\PayPalConfiguration;
24+
25+
class VenmoPaymentSourceNodeBuilder implements VenmoPaymentSourceNodeBuilderInterface
26+
{
27+
/**
28+
* @var string
29+
*/
30+
private $paypalVaultId;
31+
32+
/**
33+
* @var string
34+
*/
35+
private $paypalCustomerId;
36+
37+
/**
38+
* @var bool
39+
*/
40+
private $savePaymentMethod;
41+
42+
/**
43+
* @var array
44+
*/
45+
private $cart;
46+
47+
/**
48+
* {@inheritDoc}
49+
*/
50+
public function build(): array
51+
{
52+
$data = ['email_address' => (string) $this->cart['customer']->email];
53+
54+
if ($this->savePaymentMethod) {
55+
$data['attributes']['vault'] = [
56+
'store_in_vault' => 'ON_SUCCESS',
57+
'usage_pattern' => 'IMMEDIATE',
58+
'usage_type' => 'MERCHANT',
59+
'customer_type' => 'CONSUMER',
60+
'permit_multiple_payment_tokens' => false,
61+
];
62+
if ($this->paypalCustomerId) {
63+
$data['attributes']['customer'] = [
64+
'id' => $this->paypalCustomerId,
65+
];
66+
}
67+
}
68+
69+
if ($this->paypalVaultId) {
70+
$data['vault_id'] = $this->paypalVaultId;
71+
}
72+
73+
return [
74+
'payment_source' => [
75+
'venmo' => $data,
76+
],
77+
];
78+
}
79+
80+
/** {@inheritDoc} */
81+
public function setPaypalVaultId($paypalVaultId): self
82+
{
83+
$this->paypalVaultId = $paypalVaultId;
84+
85+
return $this;
86+
}
87+
88+
/** {@inheritDoc} */
89+
public function setPaypalCustomerId($paypalCustomerId): self
90+
{
91+
$this->paypalCustomerId = $paypalCustomerId;
92+
93+
return $this;
94+
}
95+
96+
/** {@inheritDoc} */
97+
public function setSavePaymentMethod(bool $savePaymentMethod): self
98+
{
99+
$this->savePaymentMethod = $savePaymentMethod;
100+
101+
return $this;
102+
}
103+
104+
/** {@inheritDoc} */
105+
public function setCart(array $cart)
106+
{
107+
$this->cart = $cart;
108+
109+
return $this;
110+
}
111+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
/**
3+
* Copyright since 2007 PrestaShop SA and Contributors
4+
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
5+
*
6+
* NOTICE OF LICENSE
7+
*
8+
* This source file is subject to the Academic Free License version 3.0
9+
* that is bundled with this package in the file LICENSE.md.
10+
* It is also available through the world-wide-web at this URL:
11+
* https://opensource.org/licenses/AFL-3.0
12+
* If you did not receive a copy of the license and are unable to
13+
* obtain it through the world-wide-web, please send an email
14+
* to license@prestashop.com so we can send you a copy immediately.
15+
*
16+
* @author PrestaShop SA and Contributors <contact@prestashop.com>
17+
* @copyright Since 2007 PrestaShop SA and Contributors
18+
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
19+
*/
20+
21+
namespace PsCheckout\Core\Order\Builder\Node\PaymentSource;
22+
23+
interface VenmoPaymentSourceNodeBuilderInterface
24+
{
25+
/**
26+
* @return array
27+
*/
28+
public function build(): array;
29+
30+
/**
31+
* @param string|null $paypalVaultId
32+
*
33+
* @return VenmoPaymentSourceNodeBuilder
34+
*/
35+
public function setPaypalVaultId($paypalVaultId): VenmoPaymentSourceNodeBuilder;
36+
37+
/**
38+
* @param string|null $paypalCustomerId
39+
*
40+
* @return VenmoPaymentSourceNodeBuilder
41+
*/
42+
public function setPaypalCustomerId($paypalCustomerId): VenmoPaymentSourceNodeBuilder;
43+
44+
/**
45+
* @param bool $savePaymentMethod
46+
*
47+
* @return VenmoPaymentSourceNodeBuilder
48+
*/
49+
public function setSavePaymentMethod(bool $savePaymentMethod): VenmoPaymentSourceNodeBuilder;
50+
51+
/**
52+
* @param array $cart
53+
*
54+
* @return $this
55+
*/
56+
public function setCart(array $cart);
57+
}

0 commit comments

Comments
 (0)