diff --git a/packages/Webkul/Paypal/src/Http/Controllers/SmartButtonController.php b/packages/Webkul/Paypal/src/Http/Controllers/SmartButtonController.php index e63d21ad8..b8007334b 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 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..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,19 +299,19 @@ 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.unshift(image) + galleryImages.push(image) }); this.config.variant_videos[this.simpleProduct].forEach(function(video) { - galleryImages.unshift(video) + galleryImages.push(video) }); } + + this.galleryImages.forEach(function(image) { + galleryImages.push(image) + }); }, changeStock: function (productId) { 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) }); }