【问题标题】:How to implement 'server side' Stripe code into Android App using SQLite如何使用 SQLite 在 Android 应用程序中实现“服务器端”条带代码
【发布时间】:2017-02-01 06:29:57
【问题描述】:

我能够使用 Stripes Android Walkthrough 创建一个令牌。但现在我想创建一个客户,并最终向他们展示如何在您的服务器上进行收费here。但是我将 SQLite 用于我的数据库,因为这个应用程序只会被少数人使用,并且只能由我加载到单个平板电脑上。所以我的问题是我可以在我的应用程序中创建一个客户,而不必在我的应用程序中构建整个服务器端后端吗?

这是我创建令牌的代码,现在我想使用该令牌创建一个客户:(忽略应用程序的混乱,抱歉,最终应用程序会更干净,只是想看看我能不能得到它工作)

package com.zeuspwr.zeuspower;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Spinner;
import android.widget.Toast;

import com.stripe.android.*;
import com.stripe.android.model.Card;
import com.stripe.android.model.Token;
import com.stripe.android.Stripe;

import java.util.HashMap;
import java.util.Map;

public class newUser extends AppCompatActivity {
    EditText fNameh;
    EditText lNameh;
    EditText emailh;
    EditText phoneNumh;
    EditText pinh;
    EditText cardNumberh;
    EditText cardCVCh;
    Spinner cardExpMonthh;
    Spinner cardExpYearh;
    String fname;
    String lname;
    String email;
    String phonenum;
    String pin;
    String cardNumber;
    String cardCVC;
    Integer cardExpMonth;
    Integer cardExpYear;
    String stripetok;
    Card cardNew;

    String cardExpMonthStr;
    String cardExpYearStr;

    private static final String PUBLISHABLE_KEY = "pk_test_iUVdhdvJuurqSxIlXpzq32LS";
    UserDBHelper newUserr;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_new_user);

        newUserr = new UserDBHelper(newUser.this);

        fNameh = (EditText) findViewById(R.id.fNameNew);
        lNameh = (EditText) findViewById(R.id.lNameNew);
        emailh = (EditText) findViewById(R.id.emailNew);
        phoneNumh = (EditText) findViewById(R.id.phoneNew);
        pinh = (EditText) findViewById(R.id.pinNew);
        cardNumberh = (EditText) findViewById(R.id.cardNumNew);
        cardCVCh = (EditText) findViewById(R.id.cvcNew);
        cardExpMonthh = (Spinner) findViewById(R.id.monthNew);
        cardExpYearh = (Spinner) findViewById(R.id.yearNew);


        ImageButton createNewUser = (ImageButton) findViewById(R.id.createNew);



        createNewUser.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v)
            {

                fname = fNameh.getText().toString();
                lname = lNameh.getText().toString();
                email = emailh.getText().toString();
                phonenum = phoneNumh.getText().toString();
                pin = pinh.getText().toString();
                cardNumber = cardNumberh.getText().toString();
                cardCVC = cardCVCh.getText().toString();
                cardExpMonthStr = cardExpMonthh.getSelectedItem().toString();
                cardExpYearStr = cardExpYearh.getSelectedItem().toString();
                cardExpMonth = Integer.valueOf(cardExpMonthStr);
                cardExpYear = Integer.valueOf(cardExpYearStr);

                cardNew = new Card(
                        cardNumber,
                        cardExpMonth,
                        cardExpYear,
                        cardCVC
                );

                if(cardNew.validateCard() & cardNew.validateCVC()) {
                    final Stripe stripe = new Stripe();
                    stripe.createToken(cardNew, PUBLISHABLE_KEY, new TokenCallback() {
                        public void onSuccess(Token token) {
                            // TODO: Send Token information to your backend to initiate a charge


                            Toast.makeText(
                                    getApplicationContext(),
                                    "Token created: " + token.getId(),
                                    Toast.LENGTH_LONG).show();
                        }

                        public void onError(Exception error) {
                            Log.d("Stripe", error.getLocalizedMessage());
                        }
                    });

                }

                else{
                    Toast.makeText(
                            getApplicationContext(),
                            "Token not made!",
                            Toast.LENGTH_LONG).show();
                }



                /*Intent retPage = new Intent(BorroworReturn.this, returno.class);

                startActivity(retPage);*/
            }
        });

【问题讨论】:

    标签: java android sqlite stripe-payments


    【解决方案1】:

    很遗憾,您无法在您的 Android 应用程序中执行上述任何操作,因为这些调用需要您的 API 密钥。您绝不应该在您的 Android 应用程序中使用 Secret API 密钥,否则攻击者可能会得到它,然后代表您创建费用、退款或转账。

    您需要在此处首先创建一个卡令牌(您已这样做),然后将其发送到您的服务器,您将在服务器上使用您的密钥创建费用或客户。在您的 Android 应用程序中不会发生这种情况。

    您可以参考这个其他问题:the correct way of sending a stripe token with Android 来检查一些有关如何向您的服务器发送令牌的 Android 代码。

    在服务器端,您需要检索令牌,然后使用它来创建 ChargeCustomer

    【讨论】:

      猜你喜欢
      • 2016-01-07
      • 1970-01-01
      • 1970-01-01
      • 2013-02-01
      • 1970-01-01
      • 2013-07-25
      • 1970-01-01
      • 2015-11-20
      • 2018-04-22
      相关资源
      最近更新 更多