I want to integrate a Razorpay monthly subscription to my app but I can't achieve that by reading docs of Razorpay android SDK integration, it is too much confusing and lacks information about how to use their services. not proper and complete demo for referring and understanding about it.
I want to know which steps I should follow for a recurring payment system using Razorpay.
**most of the confusing things are **
status
of subscription after checkout.next Due
of subscription.- How to
renew
a subscription. entity
What to add and what to not.start_at
andend_at
add manually?- Can we create 10 min subscription for testing as what we want?
what I have done for that.
- Initialize Object.
- Create a plan in the dashboard.
- Create a subscription(don't know about
start_at
entity). - Checkout using
subscription_id
.
Guide me if anyone has done this before, a helping hand will be appreciated
What I have tried
Create a subscription
// Calender API ( to set future date after 3 days)
val calendar = Calendar.getInstance()
calendar[Calendar.HOUR] = 0
calendar[Calendar.MINUTE] = 0
calendar[Calendar.SECOND] = 0
calendar.add(Calendar.DATE, 3)
Log.d(TAG, "calendar: " + calendar.time)
// ------------
// ------------
val requestJSON = JSONObject()
requestJSON.put("plan_id", keyPlan)
requestJSON.put("total_count", 1)
requestJSON.put("quantity", 1)
requestJSON.put("start_at", calendar.timeInMillis / 1000)
val notesJSON = JSONObject()
notesJSON.put(
"name",
activity.resources.getString(com.razorpay.R.string.app_name)
)
notesJSON.put(
"email",
""
)
requestJSON.put("notes", notesJSON)
val subscription: Subscription =
razorpayClient.subscriptions.create(requestJSON)
subscriptionResponse = Gson().fromJson(
subscription.toString(),
SubscriptionResponse::class.java
)
editor.putString("_id", subscriptionResponse.id)
editor.commit()
Checkout created subscription
val options = JSONObject()
options.put(
"name",
activity.resources.getString(com.razorpay.R.string.app_name)
)
options.put("description", "1 Month Subscription")
options.put("subscription_id", sharePref.getString("_id", ""))
val prefill = JSONObject()
prefill.put(
"email",
""
)
options.put("prefill", prefill)
val readOnly = JSONObject()
// readOnly.put("contact", true);
readOnly.put("email", true)
options.put("readonly", readOnly)
options.put(
"image",
""
)
options.put("theme.color", "#080637")
val retryObj = JSONObject()
retryObj.put("enabled", true)
retryObj.put("max_count", 3)
options.put("retry", retryObj)
activity.runOnUiThread {
checkout.open(activity, options)
}