title: Stripe payment gateway in android
body: <p>I am integrating Stripe in my android application. 
  I have found two issues and I am stuck.</p>
  
  <p><strong>First (and major) issue is -</strong> 
  I have got token key from the card information. But when I tried to make my first charge, it shows error in following line.</p>
  
  <pre><code>Stripe.apiKey = "sk_test_0000000000000";
  </code></pre>
  
  <p>I have googled also but couldn't find any solution. </p>
  
  <p><a href="https://stackoverflow.com/questions/31768006/creating-stripe-customer-cannot-resolve-symbol-apikey">Creating Stripe Customer - cannot resolve symbol apiKey</a></p>
  
  <p>I have even seen this kind of question too. But I failed to understand its solution. </p>
  
  <p>Following is my code for making charge:</p>
  
  <pre><code>    final String publishableApiKey = BuildConfig.DEBUG ?
              "pk_test_000000000000000000" :
              //"sk_test_00000000000000000000000" :
              getString(R.string.com_stripe_publishable_key);
  
      final TextView cardNumberField = (TextView) findViewById(R.id.cardNumber);
      final TextView monthField = (TextView) findViewById(R.id.month);
      final TextView yearField = (TextView) findViewById(R.id.year);
      TextView cvcField = (TextView) findViewById(R.id.cvc);
  
      Card card = new Card(cardNumberField.getText().toString(),
              Integer.valueOf(monthField.getText().toString()),
              Integer.valueOf(yearField.getText().toString()),
              cvcField.getText().toString());
  
      Stripe stripe = new Stripe();
      stripe.createToken(card, publishableApiKey, new TokenCallback() {
          public void onSuccess(Token token) {
              // TODO: Send Token information to your backend to initiate a charge
              Toast.makeText(
                      getApplicationContext(),
                      "Charge Token created: " + token.getId(),
                      Toast.LENGTH_LONG).show();
  
  
              /*make a charge starts*/
  
              // Set your secret key: remember to change this to your live secret key in production
              // Create the charge on Stripe's servers - this will charge the user's card
              Stripe.apiKey = "sk_test_0000000000000000000000";
              try {
                  Map&lt;String, Object&gt; chargeParams = new HashMap&lt;String, Object&gt;();
                  chargeParams.put("amount", 100); // amount in cents, again
                  chargeParams.put("currency", "usd");
                  chargeParams.put("source", token.getId());
                  chargeParams.put("description", "Example charge");
  
                  Charge charge = Charge.create(chargeParams);
                  System.out.println("Charge Log :" + charge);
              } catch (CardException e) {
                  // The card has been declined
              } catch (APIException e) {
                  e.printStackTrace();
              } catch (AuthenticationException e) {
                  e.printStackTrace();
              } catch (InvalidRequestException e) {
                  e.printStackTrace();
              } catch (APIConnectionException e) {
                  e.printStackTrace();
              }
  
              /*charge ends*/
          }
  </code></pre>
  
  <p>I have tried these code from different examples. I followed Stripe doc too.</p>
  
  <p>But I got this error:</p>
  
  <blockquote>
    <p>com.stripe.exception.AuthenticationException: No API key provided. (HINT: set your API key using 'Stripe.apiKey = '.</p>
  </blockquote>
  
  <p><strong>Second Issue is - about validation.</strong> 
  If I am entering my own card details, and if I write wrong cvv number. It still generates token key. </p>
  
  <p>I have already implemented validation of fields using Stripe's official doc. I don't know how to validate it with real time data.</p>
  
  <p><strong>Solution for the First Issue:</strong> </p>
  
  <pre><code> com.stripe.Stripe.apiKey = "sk_test_xxxxxxxxxxxxxxxxxxx";
                          try {
                              final Map&lt;String, Object&gt; chargeParams = new HashMap&lt;String, Object&gt;();
                              chargeParams.put("amount", 500); // amount in cents, again
                              chargeParams.put("currency", "usd");
                              chargeParams.put("source", token.getId());
                              chargeParams.put("description", "Example charge");
                              new Thread(new Runnable() {
                                  @Override
                                  public void run() {
                                      Charge charge = null;
                                      try {
                                          charge = Charge.create(chargeParams);
                                      } catch (AuthenticationException e) {
                                          e.printStackTrace();
                                      } catch (InvalidRequestException e) {
                                          e.printStackTrace();
                                      } catch (APIConnectionException e) {
                                          e.printStackTrace();
                                      } catch (CardException e) {
                                          e.printStackTrace();
                                      } catch (APIException e) {
                                          e.printStackTrace();
                                      }
                                      System.out.println("Charge Log :" + charge);
                                  }
                              }).start();
  
                          } catch (Exception e) {
                              e.printStackTrace();
                          }
  </code></pre>