Skip to content Skip to sidebar Skip to footer

Rails / Stripe - Taking Multiple Payments

I'm building an events app using Rails and Stripe to handle payments. I've used javascript for my booking page in order to allow a user to book and pay for multiple spaces rather t

Solution 1:

You need to create Stripe.order and pass items: [], where you can pass quantity. In your case it will be one item.

Please check out Stripe API for more information

Update

Here step by step guide:

  1. Login to Stripe account, create a product and make it active. This will be your booking. Save it.
  2. When you inside the product, you'll see Inventory. Find + Add SKU. Click it.
  3. You'll see the popup window like this enter image description here
  4. Fill in whatever you need to. In your case currency, price and inventory, perhaps image. ID will be generated automatically. Press Add SKU
  5. Now you'll have SKU for this product. As you probably guessed already, you can have many SKU's for the same product and the price can be different.
  6. Copy newly created SKU id
  7. Now you can create Stripe::Order like this:

    response = Stripe::Order.create(
      currency: 'usd',
      items: [
        {
          type: 'sku',
          parent: 'sku_9AJ4OfKbdRuoGi', # SKU id
          quantity: 2
        }
      ],
      customer: nil,  # replace with customer id if needed
      email: 'michael.thompson@example.com'
    )
    

This is how your response would look like:

#<Stripe::Order:0x3ff36d37e2b8 id=or_18ryyuBq3wgBfJrxa44Jzm3T> JSON: {"id": "or_18ryyuBq3wgBfJrxa44Jzm3T",
  "object": "order",
  "amount": 19998,
  "amount_returned": null,
  "application": null,
  "application_fee": null,
  "charge": null,
  "created": 1473465868,
  "currency": "usd",
  "customer": null,
  "email": "michael.thompson@example.com",
  "items": [
    {"object":"order_item","amount":19998,"currency":"usd","description":"booking","parent":"sku_9AJ4OfKbdRuoGi","quantity":2,"type":"sku"},
    {"object":"order_item","amount":0,"currency":"usd","description":"Taxes (included)","parent":null,"quantity":null,"type":"tax"},
    {"object":"order_item","amount":0,"currency":"usd","description":"Free shipping","parent":"ship_free-shipping","quantity":null,"type":"shipping"}
  ],
  "livemode": false,
  "metadata": {},
  "returns": {"object":"list","data":[],"has_more":false,"total_count":0,"url":"/v1/order_returns?order=or_18ryyuBq3wgBfJrxa44Jzm3T"},
  "selected_shipping_method": "ship_free-shipping",
  "shipping": null,
  "shipping_methods": [
    {"id":"ship_free-shipping","amount":0,"currency":"usd","delivery_estimate":null,"description":"Free shipping"}
  ],
  "status": "created",
  "status_transitions": null,
  "updated": 1473465868
}

When examining the response of any API call or webhook notification, use the Order object’s status attribute to verify the current status of the order and respond accordingly.

  • When an order is first requested, the resulting order object has an initial status of created.
  • When an order is paid, status changes to paid. You should now fulfill the order.
  • After fulfilling the order, update the Order object to change status to fulfilled. Only orders in the paid state can be marked as fulfilled.
  • If the customer cancels the order (through your site) before it’s been fulfilled, update status to canceled which will refund the payment.
  • If the order has been fulfilled and the customer returns the purchased items, update status to returned which will refund the payment.

Read order guide for more details.

Now you should see new order in Stripe's dashboard

Hope this helps.

Post a Comment for "Rails / Stripe - Taking Multiple Payments"