package com.stripe.example.activity;

import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity;

import com.stripe.example.R;
import com.stripe.android.Stripe;
import com.stripe.android.TokenCallback;
import com.stripe.android.model.Card;
import com.stripe.android.model.Token;
import com.stripe.example.dialog.ErrorDialogFragment;
import com.stripe.example.dialog.ProgressDialogFragment;
import com.stripe.example.PaymentForm;
import com.stripe.example.TokenList;


public class PaymentActivity extends FragmentActivity {

    /*
     * You need to set this to your stripe test publishable key.
     *
     * For more info, see https://stripe.com/docs/stripe.js
     *
     * E.g.
     *
     *   private static final String publishableKey = "pk_something123456789";
     *
     */
    public static final String PUBLISHABLE_KEY = YOUR_PUBLISHABLE_KEY;

    private ProgressDialogFragment progressFragment;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.payment_activity);

        progressFragment = ProgressDialogFragment.newInstance(R.string.progressMessage);
    }

    public void saveCreditCard(PaymentForm form) {

        Card card = new Card(
                form.getCardNumber(),
                form.getExpMonth(),
                form.getExpYear(),
                form.getCvc());

        boolean validation = card.validateCard();
        if (validation) {
            startProgress();
            new Stripe().createToken(
                    card,
                    PUBLISHABLE_KEY,
                    new TokenCallback() {
                    public void onSuccess(Token token) {
                        getTokenList().addToList(token);
                        finishProgress();
                        }
                    public void onError(Exception error) {
                            handleError(error.getLocalizedMessage());
                            finishProgress();
                        }
                    });
        } else {
            handleError("You did not enter a valid card");
        }
    }

    private void startProgress() {
        progressFragment.show(getSupportFragmentManager(), "progress");
    }

    private void finishProgress() {
        progressFragment.dismiss();
    }

    private void handleError(String error) {
        DialogFragment fragment = ErrorDialogFragment.newInstance(R.string.validationErrors, error);
        fragment.show(getSupportFragmentManager(), "error");
    }

    private TokenList getTokenList() {
        return (TokenList)(getSupportFragmentManager().findFragmentById(R.id.token_list));
    }
}

@@ -597,23 +597,14 @@
   * 
-You need to set
+Change
  thi
@@ -617,20 +617,8 @@
 our 
-stripe test 
 publ
@@ -628,17 +628,17 @@
 able key
-.
+!
 %0A     *%0A
@@ -648,26 +648,28 @@
   * 
-For more info, see
+You can get it here:
  htt
@@ -673,16 +673,23 @@
 https://
+manage.
 stripe.c
@@ -695,134 +695,23 @@
 com/
-docs/stripe.js%0A     *%0A     * E.g.%0A     *%0A     *   private static final String publishableKey = %22pk_something123456789%22;%0A     *
+account/apikeys
 %0A   
@@ -768,28 +768,42 @@
 Y = 
-YOUR_PUBLISHABLE_KEY
+%22pk_test_6pRNASCoBOKtIshFeQd4XMUh%22
 ;%0A%0A 

Embed the default publishable key to mirror iOS and also have the project build by default.