strip发布多个项目的密钥

xam8gpfp  于 2021-07-06  发布在  Java
关注(0)|答案(0)|浏览(272)

我刚开始使用stripe,我在这个问题上坚持了一个星期,我已经获得了实时可发布的密钥和秘密密钥,在我添加了卡的详细信息后,我得到了错误:请注意:密钥也用于我们的一个ios项目,api在ios上运行良好,但在android上失败,我甚至在postman上进行了测试,然后卡片就被添加了。我不确定我是否在代码中遗漏了什么,或者是服务器问题。非常感谢您的帮助!

<-- 500 Internal Server Error https://ABCD.com/api/user/card (988ms)
    Date: Fri, 11 Dec 2020 08:57:31 GMT
D/OkHttp: Server: Apache
    Cache-Control: no-cache, private
    X-RateLimit-Limit: 60
D/OkHttp: X-RateLimit-Remaining: 59
D/OkHttp: Vary: Authorization
    Connection: close
    Transfer-Encoding: chunked
D/OkHttp: Content-Type: application/json
D/OkHttp: {"error":"Your card was declined."}

当我阅读stripe文档时,它说500个错误来自stripe服务器端。
下面是调用和获取响应的活动:函数addcardtoaccount()被编码为添加一张卡并将数据发送到服务器,即卡号和条带令牌,我获取正确的令牌和卡号,但它失败并且没有返回成功的响应。它进入else循环并返回“您的卡已被拒绝”

public class AddCardActivity extends AppCompatActivity {

    String Card_Token = "";
    String Card_Number="";
    CustomDialog customDialog;

    static final Pattern CODE_PATTERN = Pattern
            .compile("([0-9]{0,4})|([0-9]{4}-)+|([0-9]{4}-[0-9]{0,4})+");
    @BindView(R.id.card_form)
    CardForm cardForm;
    @BindView(R.id.addCard)
    Button addCard;
    @BindView(R.id.activity_add_card)
    LinearLayout activityAddCard;
    Context context;
    Activity activity;
    ApiInterface apiInterface = ApiClient.getRetrofit().create(ApiInterface.class);
    @BindView(R.id.toolbar)
    Toolbar toolbar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setTheme(R.style.Mytheme);
        setContentView(R.layout.activity_add_card);
        ButterKnife.bind(this);
        context = AddCardActivity.this;
        activity = AddCardActivity.this;
        setSupportActionBar(toolbar);
        toolbar.setNavigationIcon(R.drawable.ic_back);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        cardForm.cardRequired(true)
                .expirationRequired(true)
                .cvvRequired(true)
                .postalCodeRequired(false)
                .mobileNumberRequired(false)
                .actionLabel("Add CardDetails")
                .setup(activity);

        addCard.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                customDialog = new CustomDialog(context);
                customDialog.setCancelable(false);
                if (customDialog != null)
                    customDialog.show();
                if (cardForm.getCardNumber() == null || cardForm.getExpirationMonth() == null || cardForm.getExpirationYear() == null || cardForm.getCvv() == null) {
                    if ((customDialog != null) && (customDialog.isShowing()))
                        customDialog.dismiss();
                    displayMessage(context.getResources().getString(R.string.enter_card_details));
                } else {
                    if (cardForm.getCardNumber().equals("") || cardForm.getExpirationMonth().equals("") || cardForm.getExpirationYear().equals("") || cardForm.getCvv().equals("")) {
                        if ((customDialog != null) && (customDialog.isShowing()))
                            customDialog.dismiss();
                        displayMessage(context.getResources().getString(R.string.enter_card_details));
                    } else {
                        final String cardNumber = cardForm.getCardNumber();
                        int month = Integer.parseInt(cardForm.getExpirationMonth());
                        int year = Integer.parseInt(cardForm.getExpirationYear());
                        String cvv = cardForm.getCvv();
                        Utils.print("MyTest", "CardDetails Number: " + cardNumber +
                                "Month: " + month + " Year: " + year);

                        final Card card = new Card(cardNumber, month, year, cvv);
                        try {
                            Stripe stripe = new Stripe(AddCardActivity.this, BuildConfigure.STRIPE_PK);
                            stripe.createToken(
                                    card,
                                    new TokenCallback() {
                                        public void onSuccess(Token token) {
                                            // Send token to your server
                                            Utils.print("CardToken:", " " + token.getId());
                                            Log.e("Token", String.valueOf(token));
                                            Log.e("TokenID",token.getId());
                                            Utils.print("CardToken:", " " + token.getCard().getLast4());
                                            Card_Token = token.getId();
                                            Card_Number=card.getNumber();
                                           Long card_number= Long.parseLong(Card_Number);
                                            addCardToAccount(Card_Token,Card_Number);
                                        }

                                        public void onError(Exception error) {
                                            // Show localized error message
                                            displayMessage(context.getResources().getString(R.string.enter_card_details));
                                            if ((customDialog != null) && (customDialog.isShowing()))
                                                customDialog.dismiss();
                                        }
                                    }
                            );
                        } catch (Exception e) {
                            e.printStackTrace();
                            if ((customDialog != null) && (customDialog.isShowing()))
                                customDialog.dismiss();
                        }
                    }

                }
            }
        });

    }

public void addCardToAccount(final String cardToken, final String cardNumber) {
    Log.e("stripe_token", cardToken);
    Log.e("cardNumber", String.valueOf(cardNumber));
    Call<Message> call = apiInterface.addCard(cardToken,cardNumber);
    call.enqueue(new Callback<Message>() {
        @Override
        public void onResponse(@NonNull Call<Message> call, @NonNull Response<Message> response) {
            customDialog.dismiss();
            if (response.isSuccessful()) {
                Toast.makeText(context, "" + response.body().getMessage(), Toast.LENGTH_SHORT).show();
                finish();
            } else {
                try {
                    JSONObject jObjError = new JSONObject(response.errorBody().string());
                    Toast.makeText(context, jObjError.optString("error"), Toast.LENGTH_LONG).show();
                } catch (Exception e) {
                    Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show();
                }
            }
        }

        @Override
        public void onFailure(@NonNull Call<Message> call, @NonNull Throwable t) {
            Toast.makeText(AddCardActivity.this, "Something went wrong", Toast.LENGTH_SHORT).show();
            customDialog.dismiss();
            Toast.makeText(context, "Something went wrong", Toast.LENGTH_SHORT).show();
        }
    });

}

}
api是:

@FormUrlEncoded
@POST("api/user/card")
Call<Message> addCard(@Field("stripe_token") String stripeToken, @Field("number") String cardNumber );

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题