Creating a payment using Sources with the Android SDK is a multi-step process:
- Create a Source object that represents your customer’s payment method.
- Check if further action is required from your customer.
If no further action is required:
- Confirm the source is ready to use.
- Create a charge request on your backend using the source.
If further action is required:
- Present the user with any information they may need to authorize the charge.
- On your backend, listen to Stripe webhooks to create a charge with the source.
- In your app, display the appropriate confirmation to your customer based on the source’s status.
Redirect your customer to authorize a source
For sources that require your customer to complete an action (for example, verify using 3D Secure), redirect the customer out of your application to complete this step.
Once the customer has completed the required action, they are redirected to the URL that was provided when creating the source.
When declaring your activity that creates redirect-based sources, list an
intent-filter item in your
AndroidManifest.xml file. This allows you to accept links into your application. Your activity must include
android:launchMode="singleTask" or else a new copy of it is opened when your customer comes back from the browser.
<activity android:name=".activity.PollingActivity" android:launchMode="singleTask" android:theme="@style/SampleTheme"> <intent-filter> <action android:name="android.intent.action.VIEW"/> <category android:name="android.intent.category.DEFAULT"/> <category android:name="android.intent.category.BROWSABLE"/> <data android:scheme="yourapp" android:host="post-authentication-return-url"/> </intent-filter> </activity>
To receive information from this event, listen for your activity getting started back up with a new Intent using the
onNewIntent lifecycle method.
If you’d like more help, check out the example app on Github that demonstrates creating a payment using several different payment methods.