Использование Rails 5.02, Ruby 2.3, с гемом Stripe 'stripe'
Мой код для вычета комиссии выглядит следующим образом:
begin
# Use Stripe's library to make requests...
charge = Stripe::Charge.create(
:customer => 1234,
:amount => 100, ## i.e 1$
:description => "job payment",
:currency => 'usd',
capture: false,
metadata: {'transaction' => transaction_id},
)
if !charge.review
charge.capture
end
if charge.paid?
@job_payment.invoice_id = transaction_id
@job_payment.transaction_date = Time.now
@job_payment.save
@job.update(job_payment_status: 'paid', expiry_date: Time.now + 30.days)
puts 'Job Payment.....'
job_payment_done_email(@job, @job_payment.invoice_id)
end
rescue Stripe::CardError => e
flash[:error] = "Insufficient funds!"
Rails.logger.info '***********Begin Exception*********'
Rails.logger.info e
Rails.logger.info "Amount = " + @amount.to_s
Rails.logger.info '***********End Exception*********'
rescue Stripe::RateLimitError => e
# Too many requests made to the API too quickly
flash[:error] = "Too many requests made to the API too quickly!"
rescue Stripe::InvalidRequestError => e
# Invalid parameters were supplied to Stripe's API
flash[:error] = "Invalid parameters were supplied to payment gateway!"
rescue Stripe::AuthenticationError => e
# Authentication with Stripe's API failed
flash[:error] = "Payment authentication problem!"
rescue Stripe::APIConnectionError => e
# Network communication with Stripe failed
flash[:error] = "Payment can not be completed due to the network problem with payment gateway!"
rescue Stripe::StripeError => e
# Display a very generic error to the user, and maybe send
# yourself an email
flash[:error] = "Something went wrong inside server while payment in stripe!"
rescue => e
# Something else happened, completely unrelated to Stripe
flash[:error] = "Something went wrong inside server while payment!"
end
Транзакция застревает, давая следующееошибка недостаточного баланса:
(статус 402) (Запрос req_QPLfwLnwBf2OeY) На вашей карте недостаточно средств.
Вместо этого, если сумма была меньше желаемой, тогда он должен был сказать, что на js всплывает сам, но он выдает эту ошибку на стороне сервера, но в карте уже есть сумма в 1000 рупий.