Suraj Bahadur
Suraj Bahadur

Reputation: 3928

How To Charge Card In Stripe Using Java(Android)

After searching lot's of asked questions regarding the charging the card using stripe. Most of the question are not answer yet and not able to find the way to charge the payment.

Here what i did in my project: I am able to successfully got the token from stripe server.

  try {
        carToSave = mCardInputWidget.getCard();

        Log.d(TAG, carToSave.toString());

        if (carToSave == null) {
            Toast.makeText(this, "Please fill information", Toast.LENGTH_SHORT).show();
        } else {
            //get key from https://dashboard.stripe.com/account/apikeys
            Stripe stripe = new Stripe(StripeActivity.this, "put key here");
            stripe.createToken(carToSave, new TokenCallback() {
                @Override
                public void onError(Exception error) {
                    // Show localized error message
                    Log.d(TAG, "onError");

                }

                @Override
                public void onSuccess(Token token) {
                    //do charge with token

                    Log.d(TAG, token.getId());//token



                }
            });
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
  1. I have spend lot's of hours on Creating Charges Official docs and in the official docs they were using Charge class to charge the card but this class is not included in latest docs.

  2. Here are the link of previously asked question on stack-overflow but not contain any relevant answer that's why i am posting this answer. Link 1 Link 2

3.I have followed the Official Stripe Github but left with empty hand.

Note: Most of docs are using Charge class but that class not included in latest sdk of stripe.

Upvotes: 1

Views: 1686

Answers (4)

DCD
DCD

Reputation: 335

The same issue for me. The problem for me started today in the demo account after having managed to take the process to the end. This leads me to conclude that either is some stripe problem. The process of obtaining the token is as simple as that shown in the Suraj Bahadur code. In the Stripe dashboard, the token request is immediately indicated, but the token does not reach the device that requested it.

Upvotes: 0

Insane Developer
Insane Developer

Reputation: 1102

I also had the same issue, so I had a look at this post. The Charge class and, Stripe.api key all available in its Java SDK.

implementation 'com.stripe:stripe-java:5.36.0'

Upvotes: 2

postmoderngres
postmoderngres

Reputation: 386

You should never create a charge from within your Android mobile app. In order to create a charge, you need to use your secret API key. Your secret API should never ever be kept in a mobile application because someone could retrieve this key and they would be able to create charges and refunds on your Stripe account.

You can create charges in your server-side code like in this Stripe example backend: https://github.com/stripe/example-ios-backend/blob/0adc94abc7e2e78464e027e510da3d99152b13e6/web.rb#L34

Upvotes: 1

Babul
Babul

Reputation: 1224

plz follow this I got it from stripe payment doc, here is the link :https://stripe.com/docs/charges after getting the token from stripe server use as request param. you use the String token = request.getParameter("token")

enter image description here

Upvotes: -1

Related Questions