lib/moneytree/payment_provider/stripe.rb in moneytree-rails-0.1.10 vs lib/moneytree/payment_provider/stripe.rb in moneytree-rails-0.1.11
- old
+ new
@@ -24,11 +24,11 @@
def scope
PERMISSION.to_s
end
- def charge(amount, details, app_fee_amount: 0, description: "Charge for #{account.name}", metadata:)
+ def charge(amount, details, metadata:, app_fee_amount: 0, description: "Charge for #{account.name}")
# `source` is obtained with Stripe.js; see https://stripe.com/docs/payments/accept-a-payment-charges#web-create-token
response = ::Stripe::Charge.create(
{
amount: (amount * 100).to_i,
currency: account.currency_code,
@@ -43,11 +43,12 @@
TransactionResponse.new(
{ succeeded: :success, pending: :pending, failed: :failed }[response[:status].to_sym],
response[:failure_message],
{
charge_id: response[:id],
- card: response[:payment_method_details][:card]
+ card: response[:payment_method_details][:card],
+ has_application_fee: !app_fee_amount.zero?
}
)
rescue ::Stripe::StripeError => e
TransactionResponse.new(:failed, e.message)
end
@@ -56,10 +57,10 @@
response = ::Stripe::Refund.create(
{
charge: details[:charge_id],
amount: (-amount * 100).to_i,
metadata: metadata,
- refund_application_fee: Moneytree.refund_application_fee
+ refund_application_fee: details[:has_application_fee] && Moneytree.refund_application_fee
},
stripe_account: payment_gateway.psp_credentials[:stripe_user_id]
)
# succeeded, pending, or failed