From 1ed54e8e8da8161dbfa9abb0753445082a00f4e6 Mon Sep 17 00:00:00 2001 From: devansh bawari Date: Wed, 3 Mar 2021 20:06:07 +0530 Subject: [PATCH 1/5] Unshift Replaced With Push --- .../views/shop/products/view/configurable-options.blade.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/Webkul/Velocity/src/Resources/views/shop/products/view/configurable-options.blade.php b/packages/Webkul/Velocity/src/Resources/views/shop/products/view/configurable-options.blade.php index b9f3874f8..cfc132d55 100644 --- a/packages/Webkul/Velocity/src/Resources/views/shop/products/view/configurable-options.blade.php +++ b/packages/Webkul/Velocity/src/Resources/views/shop/products/view/configurable-options.blade.php @@ -319,11 +319,11 @@ if (this.simpleProduct) { this.config.variant_images[this.simpleProduct].forEach(function(image) { - galleryImages.unshift(image) + galleryImages.push(image) }); this.config.variant_videos[this.simpleProduct].forEach(function(video) { - galleryImages.unshift(video) + galleryImages.push(video) }); } From b26f3a135c1e1c283f82bd9a730f9d99c8ce90f0 Mon Sep 17 00:00:00 2001 From: devansh bawari Date: Fri, 5 Mar 2021 11:43:24 +0530 Subject: [PATCH 2/5] Unshift Replace With Push In Shop PAckage Also --- .../views/products/view/configurable-options.blade.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/Webkul/Shop/src/Resources/views/products/view/configurable-options.blade.php b/packages/Webkul/Shop/src/Resources/views/products/view/configurable-options.blade.php index 10c05b6cc..4309979ed 100755 --- a/packages/Webkul/Shop/src/Resources/views/products/view/configurable-options.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/products/view/configurable-options.blade.php @@ -305,11 +305,11 @@ if (this.simpleProduct) { this.config.variant_images[this.simpleProduct].forEach(function(image) { - galleryImages.unshift(image) + galleryImages.push(image) }); this.config.variant_videos[this.simpleProduct].forEach(function(video) { - galleryImages.unshift(video) + galleryImages.push(video) }); } }, From 2876831e6ff1e9db091f8e3fae4c81f2bb371989 Mon Sep 17 00:00:00 2001 From: devansh bawari Date: Fri, 5 Mar 2021 13:43:39 +0530 Subject: [PATCH 3/5] Order Arranged --- .../views/products/view/configurable-options.blade.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/Webkul/Shop/src/Resources/views/products/view/configurable-options.blade.php b/packages/Webkul/Shop/src/Resources/views/products/view/configurable-options.blade.php index 4309979ed..99871fb31 100755 --- a/packages/Webkul/Shop/src/Resources/views/products/view/configurable-options.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/products/view/configurable-options.blade.php @@ -299,10 +299,6 @@ changeProductImages: function () { galleryImages.splice(0, galleryImages.length) - this.galleryImages.forEach(function(image) { - galleryImages.push(image) - }); - if (this.simpleProduct) { this.config.variant_images[this.simpleProduct].forEach(function(image) { galleryImages.push(image) @@ -312,6 +308,10 @@ galleryImages.push(video) }); } + + this.galleryImages.forEach(function(image) { + galleryImages.push(image) + }); }, changeStock: function (productId) { From d787802a0fb892d4e1d6246202e93d4617433ac8 Mon Sep 17 00:00:00 2001 From: Gustavo Ayala Date: Sun, 7 Mar 2021 16:39:51 -0300 Subject: [PATCH 4/5] FIX: currencies "value"s and "phone" fields formated for API - "value" of a currencie can't have more than 2 decimal places - "phone" field can't have non-number characters. --- .../Controllers/SmartButtonController.php | 14 +++++------ packages/Webkul/Paypal/src/Payment/Paypal.php | 25 +++++++++++++++++++ 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/packages/Webkul/Paypal/src/Http/Controllers/SmartButtonController.php b/packages/Webkul/Paypal/src/Http/Controllers/SmartButtonController.php index e63d21ad8..17a8e316c 100755 --- a/packages/Webkul/Paypal/src/Http/Controllers/SmartButtonController.php +++ b/packages/Webkul/Paypal/src/Http/Controllers/SmartButtonController.php @@ -115,7 +115,7 @@ class SmartButtonController extends Controller 'phone_type' => 'MOBILE', 'phone_number' => [ - 'national_number' => $cart->billing_address->phone, + 'national_number' => $this->smartButton->formatPhone($cart->billing_address->phone), ], ], ], @@ -127,28 +127,28 @@ class SmartButtonController extends Controller 'purchase_units' => [ [ 'amount' => [ - 'value' => (float) $cart->sub_total + $cart->tax_total + ($cart->selected_shipping_rate ? $cart->selected_shipping_rate->price : 0) - $cart->discount_amount, + 'value' => $this->smartButton->formatCurrencyValue((float) $cart->sub_total + $cart->tax_total + ($cart->selected_shipping_rate ? $cart->selected_shipping_rate->price : 0) - $cart->discount_amount), 'currency_code' => $cart->cart_currency_code, 'breakdown' => [ 'item_total' => [ 'currency_code' => $cart->cart_currency_code, - 'value' => (float) $cart->sub_total, + 'value' => $this->smartButton->formatCurrencyValue((float) $cart->sub_total), ], 'shipping' => [ 'currency_code' => $cart->cart_currency_code, - 'value' => (float) ($cart->selected_shipping_rate ? $cart->selected_shipping_rate->price : 0), + 'value' => $this->smartButton->formatCurrencyValue((float) ($cart->selected_shipping_rate ? $cart->selected_shipping_rate->price : 0)), ], 'tax_total' => [ 'currency_code' => $cart->cart_currency_code, - 'value' => (float) $cart->tax_total, + 'value' => $this->smartButton->formatCurrencyValue((float) $cart->tax_total), ], 'discount' => [ 'currency_code' => $cart->cart_currency_code, - 'value' => (float) $cart->discount_amount, + 'value' => $this->smartButton->formatCurrencyValue( (float) $cart->discount_amount), ], ], ], @@ -190,7 +190,7 @@ class SmartButtonController extends Controller $lineItems[] = [ 'unit_amount' => [ 'currency_code' => $cart->cart_currency_code, - 'value' => (float) $item->price, + 'value' => $this->smartButton->formatCurrencyValue((float) $item->price), ], 'quantity' => $item->quantity, 'name' => $item->name, diff --git a/packages/Webkul/Paypal/src/Payment/Paypal.php b/packages/Webkul/Paypal/src/Payment/Paypal.php index 15b70c9eb..d5304f3fe 100755 --- a/packages/Webkul/Paypal/src/Payment/Paypal.php +++ b/packages/Webkul/Paypal/src/Payment/Paypal.php @@ -75,4 +75,29 @@ abstract class Paypal extends Payment { return true; } + + /** + * Format a currency value according to paypal's api constraints + * + * @param float|int $long + * @return float + */ + public function formatCurrencyValue($number): float + { + return round((float) $number, 2); + } + + /** + * Format phone field according to paypal's api constraints + * + * Strips non-numbers characters like '+' or ' ' in + * inputs like "+54 11 3323 2323" + * + * @param mixed $phone + * @return string + */ + public function formatPhone($phone): string + { + return preg_replace('/[^0-9]/', '', (string) $phone); + } } \ No newline at end of file From 97a20d933ab478015b731f9c1b65039240174f26 Mon Sep 17 00:00:00 2001 From: Gustavo Ayala Date: Mon, 8 Mar 2021 08:14:20 -0300 Subject: [PATCH 5/5] CHORE: clean white space --- .../Paypal/src/Http/Controllers/SmartButtonController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/Webkul/Paypal/src/Http/Controllers/SmartButtonController.php b/packages/Webkul/Paypal/src/Http/Controllers/SmartButtonController.php index 17a8e316c..b8007334b 100755 --- a/packages/Webkul/Paypal/src/Http/Controllers/SmartButtonController.php +++ b/packages/Webkul/Paypal/src/Http/Controllers/SmartButtonController.php @@ -148,7 +148,7 @@ class SmartButtonController extends Controller 'discount' => [ 'currency_code' => $cart->cart_currency_code, - 'value' => $this->smartButton->formatCurrencyValue( (float) $cart->discount_amount), + 'value' => $this->smartButton->formatCurrencyValue((float) $cart->discount_amount), ], ], ],