2016-05-24 18 views
0

私のAndroidアプリケーションにStripeを統合しています。 私は2つの問題を発見し、私は立ち往生しています。アンドロイドのストライプペイメントゲートウェイ

最初に(主な)問題は - カード情報からトークンキーを取得しました。しかし、最初のチャージをしようとすると、次の行にエラーが表示されます。

Stripe.apiKey = "sk_test_0000000000000"; 

私はグーグルでも解決策は見つかりませんでした。

Creating Stripe Customer - cannot resolve symbol apiKey

私もあまりにも質問のこの種のを見てきました。しかし、私はその解決策を理解できませんでした。続き

は、充電を行うための私のコードです:

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<String, Object> chargeParams = new HashMap<String, Object>(); 
       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*/ 
     } 

私は別の例からこれらのコードを試してみました。私はストライプの文書にも従った。

しかし、私はこのエラーを得た:

com.stripe.exception.AuthenticationException: No API key provided. (HINT: set your API key using 'Stripe.apiKey = '.

第二の問題はある - 検証について。 自分のカードの詳細を入力していて、間違ったcvv番号を書き込んでいる場合。それでもトークンキーが生成されます。

私はすでにStripeの公式ドキュメントを使用してフィールドの検証を実装しています。私はリアルタイムデータでそれを検証する方法を知らない。まず、問題のため

ソリューション:

com.stripe.Stripe.apiKey = "sk_test_xxxxxxxxxxxxxxxxxxx"; 
         try { 
          final Map<String, Object> chargeParams = new HashMap<String, Object>(); 
          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(); 
         } 
+0

@halfer - 編集をありがとう。 –

+0

heya.Charge charge = null;どのように手数料を取り入れるか。代金のための図書館はない –

答えて

1

ストライプのAndroidバインディングが唯一あなたがカード情報をトークン化しましょう。トークンが作成されたら、外部サーバーに送信して、API要求でトークンを使用できるようにする必要があります。

トークンはアプリから直接使用できません。アプリは自分の秘密鍵にアクセスできないようにする必要があります。このトークンは、あなたのアカウントにアクセスする攻撃者によって簡単に抽出される可能性があります。

Re。あなたの2番目の質問では、カードはトークンが作成されたときに銀行で検証されません(桁数の確認、有効期限の未来の確認など)。サーバー側のAPIリクエストでトークンを使用して、カードが銀行と照合される場合のみです。

+0

いいえ。見つけた。しかし、昨日私は試して、支払いがうまくいった。それはテストアカウントでしたが。 –

+0

私も自分の質問を更新しました。そこの解決策を見てください。そして、もし私が何か間違っていると私に知らせてください。 –

+0

アプリから直接APIリクエストを発行することは技術的に可能です。しかし、そうした場合、誰かがあなたの秘密のAPIキーを取得し、あなたのアカウントにアクセスするということはほぼ確実です。間違いなくこれをして、代わりに外部サーバーを使用する必要があります。 – Ywain

関連する問題