Accept Payments Using CRED on Custom Checkout

Let your customers make payments on your website or app using CRED Pay at Razorpay Custom Checkout.


Your customers can make payments using a combination of CRED coins and credit cards saved on Cred at Razorpay Custom Checkout.

Feature Request

  • This is an on-demand feature. Please raise a request with our to get this feature activated on your Razorpay account.
  • Watch this video to know how to raise a feature enablement request on the Razorpay Dashboard.
Feature Request GIF

To add CRED as a payment method, you need to:

  • Pass the app_offer parameter in Orders API.
  • Pass the method and provider parameters in .

You must create an order using Orders API. In the response, you obtain an order_id which you must pass to Checkout.

POST
/orders

amount

mandatory

integer The transaction amount, expressed in the currency subunit, such as paise (in case of INR). For example, for an actual amount of ₹299.35, the value of this field should be 29935.

currency

mandatory

string The currency in which the transaction should be made. See the

. Default is INR.

app_offer

optional

boolean Allow/do not allow customers to use CRED coins to make payments. This is used to prevent double discounting scenarios where customers have already availed discounts using voucher/coupon,and you do not want them to redeem Coins as well. Possible values:

  • true - Customer not allowed to use CRED coins to make payment.
  • false (default) - Customer can use CRED coins to make payment.

receipt

optional

string Your receipt id for this order should be passed here. Maximum length is 40 characters.

notes

optional

object Key-value pair that can be used to store additional information about the entity. Maximum 15 key-value pairs, 256 characters (maximum) each. For example, "note_key": "Beam me up Scotty”.

razorpay.createPayment({
amount: 12340,
currency: 'INR',
email: 'gaurav.kumar@example.com',
contact: '9111145678',
order_id: 'order_EAbtuXPh24LrEc',
method: 'app',
provider: 'cred'
});

Along with the other checkout options, you must pass:

method

mandatory

string The method used to make the payment. Here, it must be app.

provider

mandatory if method=app

string Name of the PSP app. Here, it must be cred.

Customers can make payments on your Android app using their CRED Coins as well as the credit cards saved on CRED. The SDK supports two flows:

Handy Tips

Ensure you have integrated with Razorpay Android SDK version 3.9.0 or higher.

For both collect and intent flow, you need to pass the app_offer parameter in the Orders API.

POST
/orders
curl -u [YOUR_KEY_ID]:[YOUR_KEY_SECRET] \
-X POST https://api.razorpay.com/v1/orders \
-H "content-type: application/json" \
-d '{
"amount": 1000,
"currency": "INR",
"receipt": "receipt#1",
"app_offer": true
}'

amount

mandatory

integer The transaction amount, expressed in the currency subunit, such as paise (in case of INR). For example, for an actual amount of ₹299.35, the value of this field should be 29935.

currency

mandatory

string The currency in which the transaction should be made. See the

. Default is INR.

app_offer

optional

boolean Allow/do not allow customers to use CRED coins to make payments. This is used to prevent double discounting scenarios where customers have already availed discounts using voucher/coupon, and you do not want them to redeem Coins as well. Possible values:

  • true: Customer not allowed to use CRED coins to make payment.
  • false (default): Customer can use CRED coins to make payment.

receipt

optional

string Your receipt id for this order should be passed here. Maximum length is 40 characters.

notes

optional

object Key-value pair that can be used to store additional information about the entity. Maximum 15 key-value pairs, 256 characters (maximum) each. For example, "note_key": "Beam me up Scotty”.

The Android SDK performs the following functions to invoke the intent on the Android device:

  • Handles the intent response from CRED
  • Opens the CRED app
  • Process the payment
  • Send success or failure response back to your app

To use this flow:

  1. .
  2. .
  3. .

Use the below code to check if the CRED app is present in the customer's Android device. Razorpay.isCredAppInstalled(activity) returns a boolean value, disclosing whether the app is present on the device or not.

if (Razorpay.isCredAppInstalled(PaymentOptions.this)) {
payWithCredBtn.setText("CRED Pay (Intent Flow)");
} else {
payWithCredBtn.setText("CRED Pay (Collect Flow)");
}

After you receive the customer's app information, send it to the Razorpay API to complete the creation step of the payment flow. Below is the payload(JSON Object) to be sent:

razorpay.submit(payload,activityObject)
JSONObject data = new JSONObject("{currency:'INR'}");
data.put("amount", 29935);
data.put("order_id", "order_DgZ26rHjbzLLY2");
data.put("email", "gaurav.kumar@example.com");
data.put("contact", "9000090000");
data.put("method", "app");
data.put("provider", "cred");
data.put("app_present", true);

method

mandatory

string The method used to make the payment. Here, it must be app.

provider

mandatory if method=app

string Name of the PSP app. Here, it must be cred.

app_present

mandatory if app=cred

boolean Based upon response from the app present function, pass the value in this field. Possible values:

  • true: Opens the CRED app on customer's device.
  • false (default): Sends a push notification to customer's device.

The PaymentResultListener or PaymentResultWithDataListener methods can be implemented the way shown in the above function or directly globally to the activity class. The functions will be implemented based on the method chosen.

Below are the sample codes for PaymentResultListener method.

razorpay.submit(data, new PaymentResultListener() {
@Override
public void onPaymentSuccess(String razorpayPaymentId) {
// Razorpay payment ID is passed here after a successful payment
}
@Override
public void onPaymentError(int code, String description) {
// Error code and description is passed here
}
});
} catch (Exception e) {
Log.e(TAG, "Error in submitting payment details", e);
}

Below are the sample codes for PaymentResultWithDataListener method.

razorpay.submit(data, new PaymentResultWithDataListener() {
@Override
public void onPaymentSuccess(String razorpayPaymentId, PaymentData paymentData) {
// razorpay payment ID and PaymentData passed here after a successful payment
}
@Override
public void onPaymentError(int code, String description) {
// Error code and description is passed here
}
});
} catch (Exception e) {
Log.e(TAG, "Error in submitting payment details", e);
}

In Collect Flow, the SDK sends a push notification to the contact number passed in the create request. Pass the following parameters to initiate a collect payment.

JSONObject data = new JSONObject();
data.put("amount", 29935);
data.put("order_id", "order_DgZ26rHjbzLLY2");
data.put("email", "gaurav.kumar@example.com");
data.put("contact", "9000090000");
data.put("method", "app");
data.put("provider", "cred ");
data.put("app_present", "false")

method

mandatory

string The method used to make the payment. Here, it must be app.

provider

mandatory if method=app

string Name of the PSP app. Here, it must be cred.

app_present

mandatory if app=cred

boolean Sets the payment flow as collect. Possible values:

  • true: Opens the Cred app on customer's device.
  • false (default): Sends a push notification to customer's device.

Customers can make payments on your iOS app using their CRED Coins as well as the credit cards saved on CRED. The SDK supports two flows:

Handy Tips

Ensure you have integrated with Razorpay iOS SDK version 1.3.5 or higher.

For both collect and intent flow, you need to pass the app_offer parameter in the Orders API.

POST
/orders
curl -u [YOUR_KEY_ID]:[YOUR_KEY_SECRET] \
-X POST https://api.razorpay.com/v1/orders \
-H "content-type: application/json" \
-d '{
"amount": 1000,
"currency": "INR",
"receipt": "receipt#1",
"app_offer": true
}'

amount

mandatory

integer The transaction amount, expressed in the currency subunit, such as paise (in case of INR). For example, for an actual amount of ₹299.35, the value of this field should be 29935.

currency

mandatory

string The currency in which the transaction should be made. See the

. Default is INR.

app_offer

optional

boolean Allow/do not allow customers to use CRED coins to make payments. This is used to prevent double discounting scenarios where customers have already availed discounts using voucher/coupon, and you do not want them to redeem Coins as well. Possible values:

  • true: Customer not allowed to use CRED coins to make payment.
  • false (default): Customer can use CRED coins to make payment.

receipt

optional

string Your receipt id for this order should be passed here. Maximum length is 40 characters.

notes

optional

object Key-value pair that can be used to store additional information about the entity. Maximum 15 key-value pairs, 256 characters (maximum) each. For example, "note_key": "Beam me up Scotty”.

In the Collect Flow, the SDK sends a push notification to the contact number passed in the create request. To initiate collect flow, send app_present the parameter as 0 while creating the payment.

let options: [String: Any] = [
"amount": 100,
"currency": "INR",
"contact": "9000090000",
"order_id": "order_FNPoKwCtPyhJOt",
"email": "gaurav.kumar@example.com",
"method": "app",
"provider": "cred",
"app_present": 0
]
razorpay?.authorize(options)

Along with the other payment creation request parameters, you must pass:

method

mandatory

string The method used to make the payment. Here, it must be app.

provider

mandatory if method=app

string Name of the PSP app. Here, it must be cred.

app_present

mandatory if app=cred

boolean Sets the payment flow as collect. Possible values:

  • 1: Opens the CRED app on the customer's device.
  • 0 (default): Sends a push notification to the customer's device.

In Intent Flow, the SDK invokes an intent, which is handled by the Cred app installed on the iOS device. Follow these steps:

You must make the following changes to your iOS app's info.plist file:

<key>LSApplicationQueriesSchemes</key>
<array>
<string>credpay</string>
</array>

  • Check if the CRED app is present on the customer's mobile using the isCredAppAvailable() method.

    /// This checks if the app is available on the device or not.
    private func isCredAppAvailable() -> Int {
    let credURIScheme = "credpay://" // This will open the CRED URL.
    if let urlString = credURIScheme.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed) {
    if let credURL = URL(string: urlString) {
    if UIApplication.shared.canOpenURL(credURL) {
    return 1
    }
    }
    }
    return 0
    }
  • CRED app listens to the URI Schema.

    credpay://

    This can be passed in the uriSchema parameter in the above function. isCredAppAvailable() returns a boolean value informing whether the app is present on the device or not.

    if (isCredAppAvailable()) {
    payWithCredBtn.setText("CRED Pay (Intent Flow)");
    } else {
    payWithCredBtn.setText("CRED Pay (Collect Flow)");
    }
  • If the CRED app is installed, pass the callback_url parameter in the payload:

    options["callback_url"] = "<MerchantApp URI-Scheme>://"

Handy Tips

The redirect happens from the CRED app based on the URL scheme passed in the payload. If not passed, the app will not redirect.

Listen to CRED callback in the AppDelegate class by implementing the open url method. Handle the success response.

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
DispatchQueue.main.asyncAfter(deadline: .now() + 4.0) {
/** Post the notification to CustomWebVC **/
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "CREDPAYURIEVENT"), object: nil, userInfo: ["response":url.absoluteString])
}
return false
}

Register for notification in CustomWebVC using the code sample given below:

NotificationCenter.default.addObserver(self, selector: #selector(self.statusCredData(_:)), name:NSNotification.Name(rawValue: "CREDPAYURIEVENT"), object: nil);

Use the code given below to handle payment data:

@objc func statusCredData(_ notification: NSNotification) {
if let dict = notification.userInfo {
if let uriScheme = dict["response"] as? String {
DispatchQueue.main.async {
self.razorpay?.publishUri(with: uriScheme)
}
}
}
}

To initiate intent flow, send the app_present parameter as 1 while creating the payment.

let options: [String:Any] = [
"amount": 100,
"currency": "INR",
"contact": "9000090000",
"order_id": "order_FNPoKwCtPyhJOt",
"email": "gaurav.kumar@example.com",
"method": "app",
"provider": "cred",
"app_present": 1,
"callback_url": "<MerchantApp URI-Scheme>://"
]
razorpay.payWithCred(options)

Along with the other payment creation request parameters, you must pass:

method

mandatory

string The method used to make the payment. Here, it must be app.

provider

mandatory if method=app

string Name of the PSP app. Here, it must be cred.

app_present

mandatory if app=cred

boolean Based upon response from the app present function, pass the value in this field. Possible values:

  • 1: Opens the CRED app on customer's device.
  • 0 (default): Sends a push notification to the customer's device.

callback_url

mandatory

string The URI scheme, using which the CRED app will be opened on the customer's mobile device.

Webhooks help a web application send information to another application in real-time when a specific event happens.

Example: If you have subscribed to the order.paid webhook event, you will receive a notification every time a user pays you for an order.

Given below are the sample payloads for payment.captured and payment.authorized applicable for CRED:


Is this integration guide useful?