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.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == MY_SCAN_REQUEST_CODE) {
        if (data != null && data.hasExtra(DyScanActivity.EXTRA_SCAN_RESULT)) {
            CreditCard scanResult = data.getParcelableExtra(DyScanActivity.EXTRA_SCAN_RESULT);
           
            // EnterCardActivity is an Activity containing Stripe's CardInputWidget
            Intent intent = new Intent(MainActivity.this, EnterCardActivity.class);
            intent.putExtra(“cardNumber”, scanResult.cardNumber);
            if(scanResult.expiryYear > 0) {
                intent.putExtra(“expiryYear”, scanResult.expiryYear);
                intent.putExtra(“expiryMonth”, scanResult.expiryMonth);
            }
            startActivity(intent);
        }
    }
}

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:

// In the Activity containing a CardInputWidget object called
// mCardInputWidget

@Override
protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_enter_card);

   mCardInputWidget = (CardInputWidget) findViewById(R.id.card_input_widget);
   Bundle b = getIntent().getExtras();

   if(b != null) {
       mCardInputWidget.setCardNumber(b.getString("cardNumber"));

       if(b.getInt("expiryYear") > 0 ) {
           mCardInputWidget.setExpiryDate(b.getInt("expiryMonth"), b.getInt("expiryYear"));
       }
   }
}

Last updated