The first step in the Subscription Checkout integration is to create a subscription. You need to do this before any payment can be processed. You can add an endpoint to your server which creates this subscription and is used for communication with your frontend.
Subscription creation must happen from your backend (as this API uses your secret key). Please do not call this directly from your mobile application. You can use below-mentioned backend SDKs
Step 2: Opening the Subscription Checkout Payment Page
Once the subscription is created, the next step is to open the payment page so the customer can make the payment. Cashfree Android SDK offer below payment flow.
To complete the payment, we can follow the following steps:
Enable Subscription flow flag in Android Manifest
Create a CFSubscriptionSession object.
Create a CFWebCheckoutTheme object (Optional).
Create a CFSubscriptionPayment object.
Set payment callback.
Initiate the payment using the payment object created from [step 3]
This object contains essential information about the subscription, including the subscription session ID (subscription_session_id) and subscription ID (subscription_id) obtained from creation step. It also specifies the environment (sandbox or production).
Copy
Ask AI
CFSubscriptionSession cfSubsSession = new CFSubscriptionSession.CFSubscriptionSessionBuilder() .setEnvironment(CFSubscriptionSession.Environment.SANDBOX) .setSubscriptionSessionID(subscription_session_id) .setSubscriptionId(subscription_id) .build();
You can customize the appearance of the checkout screen using CFWebCheckoutTheme. This step is optional but can help maintain consistency with your app’s design.
You can set the NavigationBarBackgroundColor which will set the color for status bar & cashfree loader
Copy
Ask AI
CFWebCheckoutTheme cfTheme = new CFWebCheckoutTheme.CFWebCheckoutThemeBuilder() .setNavigationBarBackgroundColor("#6A3FD3") .build();
Make sure to set the callback at activity’s onCreate as this also handles the activity restart cases.
Copy
Ask AI
public class YourActivity extends AppCompatActivity implements CFSubscriptionResponseCallback { ... @Override public void onSubscriptionVerify(CFSubscriptionResponse cfSubscriptionResponse) { } @Override public void onSubscriptionFailure(CFErrorResponse cfErrorResponse) { } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_upi_intent_checkout); try { // If you are using a fragment then you need to add this line inside onCreate() of your Fragment CFPaymentGatewayService.getInstance().setSubscriptionCheckoutCallback(this); } catch (CFException e) { e.printStackTrace(); } } ...}
Finally, call doSubscriptionPayment() to open the Cashfree Subscription checkout screen. This will present the user with the payment options and handle the payment process.
Copy
Ask AI
// replace the SubscriptionCheckoutActivity class with your class nameCFPaymentGatewayService.getInstance().doSubscriptionPayment(SubscriptionCheckoutActivity.this, cfSubscriptionPayment);
After the payment is completed, you need to confirm whether the payment was successful by checking the subscription status. Once the payment finishes, the user will be redirected back to your activity to your implementation of the CFSubscriptionResponseCallback interface.
You must always verify payment status from your backend. Before delivering the goods or services, please ensure you call check the subscription status from your backend. Ensure you check the subscription status from your server endpoint.