Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save thenishchalraj/0157ca346bbab71f6228c36687666930 to your computer and use it in GitHub Desktop.
Save thenishchalraj/0157ca346bbab71f6228c36687666930 to your computer and use it in GitHub Desktop.
Just the main functions calling the stripe's card dialog and fetching data when positive response from the user i.e. OK clicked in Java.
Dialog addCardDialog;
private void onAddCardButtonClicked() {
/*
below is kind of custom dialog
i.e. stripe widget is inside a card view and custom buttons
but the basic idea remains same
*/
addCardDialog = new Dialog(context, R.style.AppTheme_NoTitleBar_Main);
addCardDialog.setContentView(R.layout.dialog_add_card);
TextView addCard = addCardDialog.findViewById(R.id.addCard);
ImageView close = addCardDialog.findViewById(R.id.close);
close.setOnClickListener(v -> addCardDialog.dismiss());
CardInputWidget cardInputWidget = addCardDialog.findViewById(R.id.card_input_widget);
addCard.setOnClickListener(v -> {
try {
PaymentMethodCreateParams paymentMethodCreateParams =
cardInputWidget.getPaymentMethodCreateParams();
addStripeCard(paymentMethodCreateParams);
} catch (Exception e) {
e.printStackTrace();
// add a Toast to show the exception
}
});
addCardDialog.show();
}
private void addStripeCard(final PaymentMethodCreateParams paymentMethodCreateParams) {
stripe.createPaymentMethod(paymentMethodCreateParams,new ApiResultCallback<PaymentMethod>() {
@Override
public void onSuccess(@NotNull PaymentMethod result) {
Log.i("[SUCCESS] Payment Method: ", result.toString())
Log.i("[SUCCESS] Stripe Token ID: ", result.id.toString())
// add a call to own server to save the details
}
@Override
public void onError(@NotNull Exception e) {
// add a Toast to show the exception
}
});
}
@thenishchalraj
Copy link
Author

Click here to go to the blog where this was used, better explanation of how to integrate stripe in android with Java, also React Native and Kotlin code included.

Took some time in the evening to write a blog about my struggle with @stripe adding card when the card method was deprecated.

For the community. Cheers!#stripe #android #reactnative #kotlin #java #payment #card #medium #blog

Here is the link to blog:https://t.co/jvRz8ThxZP

— Nishchal Raj (@thenishchalraj) April 25, 2021

Re-tweet on Twitter.

Share on LinkedIn.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment