Created
April 25, 2021 13:56
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Re-tweet on Twitter.
Share on LinkedIn.