Integrate Offers with Standard Checkout

Integrate Offers created with Standard Checkout.


After creating offers from the Razorpay Dashboard, you have to integrate them on Razorpay Standard Checkout so that your customers can avail them while making payments.

Validation Criteria🔗

Only those offers that pass the following validations are be displayed at the Checkout:

Criteria

Description

Amount Match

Order amount should be more than or equal to the Minimum Order Amount set in an offer.

Validity

Offer should be in the active or enabled state.

Date Validation

The current date lies within the range of the start and end dates defined in the offer.

Usage

You can define the maximum number of times an offer can be availed. If this limit is met, the offer will not be displayed at the Checkout.

Show Offer on Checkout

This option must be enabled while creating the offer. This determines whether the offer will be displayed at the Checkout.

Display Offers at Checkout🔗

There are two ways in which you can display offers at Razorpay Checkout:

When Should I Integrate Offers with Orders API?
If you use any of the following Razorpay products or plugins to accept payments, you need not integrate offers with Orders API:

  • Plugins: Razorpay Magento, Shopify, or WooCommerce.
  • Products: Payment Links, Payment Buttons, Payment Pages and Invoices. This is because Razorpay automatically creates orders for these products or plugins when customers initiate payment at the Checkout.
  • However, if you use our JS, SDK files or other ecommerce plugins, you should integrate offers with the Orders API.

Method 1: Display Offers by Default🔗

This is the easiest way to display offers at the Checkout. While creating the offer from the Razorpay Dashboard, enable the Show Offer on Checkout option. Pass the order_id and trigger the Checkout.

Method 2: Display Limited Offers🔗

To display a specific offer at the Checkout, you should associate the offer with an order. You can pass the offers array as a request attribute in the Create Orders API.

Some use cases:

  • If you have multiple product lines running on the same account and have certain business logic on your side for displaying offers.
  • The discount has already been applied, and you would like to restrict the payment method to avail the offer.

To display offers:

  1. Create an Offer.
  2. Pass offer_id in Orders API.
  3. Pass order_id and Trigger Checkout.

Step 1: Create an Offer from Razorpay Dashboard🔗

You can create Offers from the Razorpay Dashboard.

Let us say you have created an offer offer_ANZoaxsOww2X53, such that a discount of ₹200 is applicable on all transactions done through AXIS netbanking only.

Handy Tips
To display an Offer for a particular customer:

  • Do not select the Show Offer on Checkout check box while creating an Offer.
  • Specify the offer_id while creating an order.

Step 2: Pass offer_id in Orders API🔗

Create an order using the Orders API and pass the offer_id as a request parameter.

Sample Code

Copycurl -u [YOUR_KEY_ID]:[YOUR_KEY_SECRET] \ -X POST https://api.razorpay.com/v1/orders \ -H "Content-Type: application/json" \ -d '{ "amount": 1000000, "currency": "INR", "offers": [ "offer_ANZoaxsOww2X53" ] }'
CopyRazorpayClient razorpay = new RazorpayClient("[YOUR_KEY_ID]", "[YOUR_KEY_SECRET]"); ArrayList Offer = new ArrayList<String>(); Offer.add("offer_JTUADI4ZWBGWur"); JSONObject orderRequest = new JSONObject(); orderRequest.put("amount", 1000000); // amount in the smallest currency unit orderRequest.put("currency", "INR"); orderRequest.put("offers", Offer); Order order = razorpayclient.orders.create(orderRequest); System.out.print(order);
Copyimport razorpay client = razorpay.Client(auth=("YOUR_ID", "YOUR_SECRET")) client.order.create({ "amount": 1000000, "currency": "INR", "receipt": "receipt#1", "offers": [ "offer_ANZoaxsOww2X53" ] })
Copy$api = new Api($key_id, $secret); $api->order->create(array('amount' => 1000000, 'currency' => 'INR', 'offers'=> array('offer_JTUADI4ZWBGWur')));
Copyrequire "razorpay" Razorpay.setup('YOUR_KEY_ID', 'YOUR_SECRET') order = Razorpay::Order.create amount: 50000, currency: 'INR', receipt: 'receipt#1', offers: [ 'offer_ANZoaxsOww2X53"' ]
Copyvar instance = new Razorpay({ key_id: 'YOUR_KEY_ID', key_secret: 'YOUR_SECRET' }) instance.orders.create({ amount: 1000000, currency: "INR", receipt: "receipt#1", offers: [ "offer_ANZoaxsOww2X53" ] })
Copyimport ( razorpay "github.com/razorpay/razorpay-go" ) client := razorpay.NewClient("YOUR_KEY_ID", "YOUR_SECRET") data := map[string]interface{}{ "amount": 50000, "currency": "INR", "receipt": "receipt#1", "offers": []interface{}{ "offer_JTUADI4ZWBGWur", }, } body, err := client.Order.Create(data, nil)
Copy{ "id": "order_CjyoZFRpB8r0AH", "entity": "order", "amount": 1000000, "amount_paid": 0, "amount_due": 1000000, "currency": "INR", "receipt": null, "offer_id": "offer_ANZoaxsOww2X53", "offers": [ "offer_ANZoaxsOww2X53" ], "status": "created", "attempts": 0, "notes": [], "created_at": 1561018912 }

Request Parameters

amount mandatory
integer Enter the amount for which the order is to be created in currency subunits. For example, for an amount of ₹10000, enter 1000000.
currency mandatory
string ISO code of the currency associated with the order amount. Here, it is INR.
offers mandatory
array Unique identifier of the offer. Pass the offer_id obtained from the response of the previous step.

Step 3: Pass Order_id and Trigger the Checkout🔗

The order_id obtained in the previous step can be passed to the Checkout form as follows:

Copy<button id="rzp-button1">Pay</button> <script src="https://checkout.razorpay.com/v1/checkout.js"></script> <script> var options = { "key": "[YOUR_KEY_ID]", "amount": "1000000", "currency": "INR", "order_id":"order_FIL1vBOsWFllnO", "name": "Acme Corp", "description": "Test Transaction", "image": "https://cdn.razorpay.com/logos/F9Yhfb7ZXjXmIQ_medium.jpg", "handler": function (response){ alert(response.razorpay_payment_id); alert(response.razorpay_order_id); alert(response.razorpay_signature) }, "prefill": { "name": "Gaurav Kumar", "email": "gaurav.kumar@example.com", "contact": "9999988999" }, "notes": { "address": "Razorpay Corporate Office" }, "theme": { "color": "#3399cc" } }; var rzp1 = new Razorpay(options); document.getElementById('rzp-button1').onclick = function(e){ rzp1.open(); e.preventDefault(); } </script>

Know more about Standard Checkout.

×