-
Notifications
You must be signed in to change notification settings - Fork 438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Apple Pay Displays Incorrect Amount for Non-Decimal Currencies (x100 Multiplication) in Spree Gateway Payment Method #412
Comments
hey @gulzarhussain112 , I also faced the same issue, and figured it out and added the patch solution for same. strpe_apple_pay.html.erb var paymentRequest = stripeApplePay.paymentRequest({
country: '<%= payment_method.preferred_country_code.try(:upcase) %>',
currency: '<%= @order.currency.downcase %>',
displayItems: [
<% @order.line_items.each do |line_item| %>
{
label: '<%= line_item.name %> x <%= line_item.quantity %>',
amount: <%= actual_amount(line_item.total, line_item.currency) %>
},
<% end %>
<% if @order.tax_total != 0 %>
{
label: '<%= Spree.t(:tax) %>',
amount: <%= actual_amount(@order.tax_total, @order.currency) %>
},
<% end %>
<% if @order.shipment_total != 0 %>
{
label: '<%= Spree.t(:shipment) %>',
amount: <%= actual_amount(@order.shipment_total, @order.currency) %>
}
<% end %>
],
total: {
label: '<%= Spree.t(:total) %>',
amount: <%= actual_amount(@order.total, @order.currency) %>
},
requestPayerName: false,
requestPayerEmail: false,
requestPayerPhone: false
}); frontend_helper.rb def actual_amount(amount, currency)
money = Spree::Money.new(amount, currency: currency)
if non_decimal_currencies.include?('JPY')
money.amount_in_cents / 100
else
money.amount_in_cents
end
end
def non_decimal_currencies
%w(JPY) # add all non decimal currencies here.
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This issue reports an incorrect displayed amount in the Apple Pay popup when using the Spree::Gateway::StripeApplePayGateway payment method provided by the Spree Gateway gem.
Problem:
When using Apple Pay with the mentioned payment method, the displayed amount in the Apple Pay popup is incorrect. Instead of showing the actual amount, it shows the amount multiplied by 100 (e.g., for ¥8000, it shows ¥800,000).
Investigation:
Identified potential cause: The issue might be related to the amount_in_cents method in the Spree Gateway gem, which converts monetary amounts to cents. The additional multiplication by 100 could lead to this discrepancy.
Expected Behaviour:
The Apple Pay popup should display the correct monetary amount without any unintended multiplications.
Reproduction Steps:
Configure the Spree::Gateway::StripeApplePayGateway payment method in Spree Commerce.
Add items to the cart and proceed to checkout.
Select the Spree::Gateway::StripeApplePayGateway payment method.
Use Apple Pay to attempt payment.
Observe the incorrect amount displayed in the Apple Pay popup.
Additional Information:
Please find the relevant code snippet in the following file
strpe_apple_pay.html.erb
This file contains the logic for calculating and displaying amounts in the Apple Pay popup.
The text was updated successfully, but these errors were encountered: