简体   繁体   中英

Android stripe save card without using CardInputWidget

My project requires to save user cards and I used Stripe for that, as per stripe's official documentation I have to use their prebuilt CardInputWidget .

Now I have some design requirements that are not matching with this Widget even after changing its theme or style.

So I am looking for any other way to save stripe card using simple edittext or create custom Card object of Stripe?

Here's the code

  implementation 'com.stripe:stripe-android:14.5.0'

Fragment code

    stripe = new Stripe(getActivity(), myApp.getStripePublishKey());
    PaymentMethodCreateParams params = card_multiline_widget.getPaymentMethodCreateParams();
        if (params == null) {
            ToastUtils.makeToast(getActivity(), "Invalid Details");
            return;
        }
        
        stripe.createPaymentMethod(params, new ApiResultCallback<PaymentMethod>() {
            @Override
            public void onSuccess(@NonNull PaymentMethod result) {
                if (getActivity() != null) {
                    getActivity().runOnUiThread(() -> progressDialog.dismiss());
                }
                paymentMethodId = result.id;
                LogUtils.e(paymentMethodId);
                saveCard();
                // Send paymentMethodId to your server for the next steps
            }

            @Override
            public void onError(@NonNull Exception e) {
                // Display the error to the user
                e.printStackTrace();
                LogUtils.e(e.getMessage());
                if (getActivity() != null) {
                    getActivity().runOnUiThread(() -> progressDialog.dismiss());
                }
            }
        });

Short

I think it's not good practice to use your own input. Prefer Stripe's one.

Explanations

Google could reject the app because of security failure.

If you use a text field for card input, you can see the card number before sending it to stripe. So you can save the full card info, in log file or else where, before getting the Stripe token.

You can do this without bad intention, but be careful if someone found it...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM