I'm using Stripe as a payment processor in my Android app and trying to charge a card as described by the documentation: https://stripe.com/docs/charges
My issue specifically is that it can not resolve Stripe.apiKey
, or can not resolve symbol apiKey
The code that I'm implementing from the documentation:
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
Stripe.apiKey = "sk_test_********************";//this is where i hit a wall
// Token is created using Stripe.js or Checkout!
// Get the payment token submitted by the form:
String token = request.getParameter("stripeToken");
// Charge the user's card:
Map<String, Object> params = new HashMap<String, Object>();
params.put("amount", 1000);
params.put("currency", "usd");
params.put("description", "Example charge");
params.put("source", token);
Charge charge = Charge.create(params);
I have also imported import com.stripe.android.*;
at the top of my file.
In my Gradle file I have imported the Stripe libraries:
compile 'com.stripe:stripe-android:2.0.2'
Why isn't Android able to resolve Stripe.apiKey
?
The code you provided is server-side Java code for creating a charge using a token. It is not meant to be used from an Android application.
A payment flow with Stripe is divided in two steps:
client-side, in your frontend code, you collect and tokenize the user's payment information (using Checkout or Stripe.js for a web application, or the iOS / Android SDKs for a native mobile application)
server-side, in your backend code, you use the resulting token in an API request, e.g. to create a charge or a customer object.
The first step is done with your publishable API key (pk_...
). The second step is done with your secret API key (sk_...
).
You must never share the secret API key with your frontend code, otherwise an attacker could retrieve it and use it to issue API requests on your behalf.
To solve Stripe.apikey cannot resolve
, change Stripe.apiKey
to
com.stripe.Stripe.apiKey = "Your secret";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With