Skip to content

Instantly share code, notes, and snippets.

@ahmad19
Last active July 11, 2020 05:12
Show Gist options
  • Save ahmad19/6acad0ffe482cb71d334bfaaa3294758 to your computer and use it in GitHub Desktop.
Save ahmad19/6acad0ffe482cb71d334bfaaa3294758 to your computer and use it in GitHub Desktop.
Use stripe to accept payment
current_user = User.last
receipt = Receipt.last
pm = Stripe::PaymentMethod.create({
type: 'card',
card: { token: 'tok_visa' }, #no PCI complaint thats why
billing_details: {
address: {
city: 'Pune',
country: receipt.customer_country,
line1: 'Somji Petrol',
postal_code: '411048',
state: 'Maharashtra'
},
email: receipt.customer_email,
name: receipt.customer_full_name,
phone: receipt.customer_phone_number
}
}, stripe_account: current_user.stripe_account_id)
customer = Stripe::Customer.create({
name: receipt.customer_full_name,
address: {
line1: 'Somji Petrol',
postal_code: '411048',
city: 'Pune',
state: 'Maharashtra',
country: receipt.customer_country,
}
}, stripe_account: current_user.stripe_account_id)
intent = Stripe::PaymentIntent.create({
payment_method_types: ['card'],
amount: (receipt.amount * 100).to_i,
currency: 'inr',
description: 'Something',
payment_method: pm.id,
customer: customer.id
}, stripe_account: current_user.stripe_account_id)
Stripe::PaymentIntent.confirm(
intent.id,
{payment_method: 'pm_card_visa'},
)
Stripe::PaymentIntent.retrieve(intent.id)
# Stripe::InvalidRequestError ((Status 404) (Request req_P1EmOmOVQiLvJ7) No such payment_intent: pi_1H3azsJdQmunzvxi6YhAx0xV)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment