Backend ordering
This guide provides step-by-step instructions for submitting an order via Rye using only a backend, without Rye Pay or any frontend components. This guide is useful for those looking to use Rye as a fulfillment API.
For some use cases, it may not make sense to collect payment info using the Rye Pay library. Perhaps you already have saved payment info, or you have another payment provider or integration configured. For these types of scenarios, it’s still possible to use the Rye API to submit an order by manually tokenizing a credit card and submitting it as part of the submitCart
input.
At a glance
- All the operations from this guide can be executed on the backend and do not require client-side code.
- You will capture funds from the shopper using whatever payment gateway you prefer.
- After capturing funds from the shopper you will place the order with Rye using the
submitCart
mutation, and pay for it using your own card.
For a live production example of creating an order using the Rye SDK in TypeScript, check out our Order from Amazon in TypeScript guide.
Step-by-step guide
1. Get a cart ready
First, we need to prepare a cart for checkout. We have a tutorial on this here. You will need to create the cart, attach the buyer’s identity, and optionally select shipping options for the store(s) you are purchasing from. Once you have a cart ready for checkout, you can return here to follow the remaining steps.
2. Capture payment from your customer
Once you have a cart prepared for checkout, you can query its cost
field to determine how much you need to charge the shopper for the order.
When using backend ordering, it is up to you to charge the shopper. You may use any payment gateway you prefer, although our recommendation is generally Stripe as it is relatively easy to get set up with them. Once you have charged the shopper you will have collected funds for the order, but the Rye cart will still be pending checkout.
3. Use Spreedly to tokenize a credit card
Next, we need to submit the cart. You can do this using the submitCart
mutation. Before you can do this, however, you will need to tokenize a payment method Rye can use to settle the order with the merchants. This should be your own card information, as you are effectively placing the order on behalf of the customer. If you were to tokenize the customer’s card here you would wind up charging the customer twice.
If you expect to push a lot of orders through Rye, then you may prefer to pay for orders via invoice instead of using a credit card. Get in touch with us to discuss this option with us.
We have a detailed tutorial on tokenizing a credit card using Spreedly here. Once you have followed that tutorial you can return here to submit the cart in the next step.
4. Submit the cart
We now have all the information we need to submit the cart! We’ll use the submitCart
mutation for this.
For our mutation, we’ll request some new fields status
and orderId
from the stores
field. These fields will be used to track the status of the order, so be sure to take a look at the status
and copy the orderId
somewhere for later. We’ll also request errors
back on the store level just in case we have an issue with placing the order.
Congrats! You’ve successfully submitted an order via Rye using backend-only code! The orderId
you copied from the response represents a Rye Order.
5. Check order status
Once we’ve successfully created an order, we can keep track of its status using two main methods:
- Receiving webhook updates from Rye (recommended)
- Polling using the
orderByID
query
While listening for webhooks is recommended in production, for the purposes of this guide we can use polling. See the OrderStatus
enum for all possible statuses.
Next steps
Congrats on making it this far! Here are some next steps you could take:
- Learn about Rye webhooks and build out a webhook integration
- Learn more about Rye by visiting our FAQs page
- Get live support as you build out your integration
Was this page helpful?