DyScan
Search…
Integrating with Stripe (Android)
If you haven't already, follow the "Importing DyScan" and "Interfacing DyScan" steps in the General Integration Guide.
Then, in your activity that launches DyScan, edit the onActivityResultfunction to look like the following.
1
@Override
2
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
3
super.onActivityResult(requestCode, resultCode, data);
4
5
if (requestCode == MY_SCAN_REQUEST_CODE) {
6
if (data != null && data.hasExtra(DyScanActivity.EXTRA_SCAN_RESULT)) {
7
CreditCard scanResult = data.getParcelableExtra(DyScanActivity.EXTRA_SCAN_RESULT);
8
9
// EnterCardActivity is an Activity containing Stripe's CardInputWidget
10
Intent intent = new Intent(MainActivity.this, EnterCardActivity.class);
11
intent.putExtra(“cardNumber”, scanResult.cardNumber);
12
if(scanResult.expiryYear > 0) {
13
intent.putExtra(“expiryYear”, scanResult.expiryYear);
14
intent.putExtra(“expiryMonth”, scanResult.expiryMonth);
15
}
16
startActivity(intent);
17
}
18
}
19
}
Copied!
Now we just need to look for these extra values in the payment information activity. This can be done by modifying the onCreate()function. For example:
1
// In the Activity containing a CardInputWidget object called
2
// mCardInputWidget
3
4
@Override
5
protected void onCreate(Bundle savedInstanceState) {
6
super.onCreate(savedInstanceState);
7
setContentView(R.layout.activity_enter_card);
8
9
mCardInputWidget = (CardInputWidget) findViewById(R.id.card_input_widget);
10
Bundle b = getIntent().getExtras();
11
12
if(b != null) {
13
mCardInputWidget.setCardNumber(b.getString("cardNumber"));
14
15
if(b.getInt("expiryYear") > 0 ) {
16
mCardInputWidget.setExpiryDate(b.getInt("expiryMonth"), b.getInt("expiryYear"));
17
}
18
}
19
}
Copied!
Last modified 2yr ago
Copy link