Menu

Integrating with Stripe (Android)


First, follow the steps in Parts I and II of our General Integration Guide.

We will assume that you have created an Activity (called EnterCardActivity in this example) with a Stripe CardInputWidget object called mCardInputWidget.

Then, in your activity that launches DyScan, edit the onActivityResult function to look like the following.


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

EnterCardActivity helloClass = new EnterCardActivity();
Intent intent = new Intent(MainActivity.this, helloClass.getClass());

   if (requestCode == 1) {
       if (data != null && data.hasExtra(DyScanActivity.EXTRA_SCAN_RESULT)) {
           CreditCard scanResult = data.getParcelableExtra(DyScanActivity.EXTRA_SCAN_RESULT);
           
           intent.putExtra(“cardNumber”,scanResult.cardNumber);
           if(scanResult.expiryYear != -1){
               intent.putExtra(“expiryYear”,scanResult.cardNumber);
               intent.putExtra(“expiryMonth”,scanResult.cardNumber);
           }
       }
   }
 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


@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"));
       }
   }
}
Get Started