Skip to content

Apple Pay Displays Incorrect Amount for Non-Decimal Currencies (x100 Multiplication) in Spree Gateway Payment Method #412

@gulzarhussain112

Description

@gulzarhussain112

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.

  • It's important to note that the incorrect amount is only shown in the Apple Pay popup. The actual charged amount by Stripe is correct, as demonstrated by the localized_amount method in the activemerchant-1.133.0 (for reference, see its code snippet below).
def localized_amount(money, currency)
  amount = amount(money)

  return amount unless non_fractional_currency?(currency) || three_decimal_currency?(currency)

  if non_fractional_currency?(currency)
     if self.money_format == :cents
        sprintf('%.0f', amount.to_f / 100)
     else
       amount.split('.').first
     end
  elsif three_decimal_currency?(currency)
     if self.money_format == :cents
       amount.to_s
     else
       sprintf('%.3f', (amount.to_f / 10))
     end
   end
end



Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions