Reputation: 1623
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
?
Upvotes: 4
Views: 2225
Reputation: 31
Import this dependency in gradle file.
implementation 'com.stripe:stripe-java:22.18.0'
Upvotes: 0
Reputation: 53
To solve Stripe.apikey cannot resolve
, change Stripe.apiKey
to
com.stripe.Stripe.apiKey = "Your secret";
Upvotes: 1
Reputation: 17503
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.
Upvotes: 8
Reputation: 1452
Try: Stripe stripe = new Stripe("pk_test_6pRNASCoBOKtIshFeQd4XMUh");
For more info check out: https://stripe.com/docs/mobile/android#credit-card-form
Upvotes: 0