交易失败.Google pay integration中的付款方式无效

时间:2018-02-28 13:45:53

标签: android sdk android-pay

我正在将Google钱包整合到我的应用程序中。我需要通过Android支付付款,因为我使用谷歌播放服务钱包sdk。 因为我必须使用假卡进行谷歌付费测试,并且我已经输入了许多假卡详细信息,但通过我除了总是交易失败。我想在沙盒环境中测试我的应用程序,以便在Live环境中进行测试。

https://github.com/google-pay/android-quickstart

  private void checkIsReadyToPay() {
    // The call to isReadyToPay is asynchronous and returns a Task. We need to provide an
    // OnCompleteListener to be triggered when the result of the call is known.
    PaymentsUtil.isReadyToPay(mPaymentsClient).addOnCompleteListener(
            new OnCompleteListener<Boolean>() {
                public void onComplete(Task<Boolean> task) {
                    try {
                        boolean result = task.getResult(ApiException.class);
                        setGooglePayAvailable(result);
                    } catch (ApiException exception) {
                        // Process error
                        Log.w("isReadyToPay failed", exception);
                    }
                }
            });
}

private void setGooglePayAvailable(boolean available) {
    // If isReadyToPay returned true, show the button and hide the "checking" text. Otherwise,
    // notify the user that Pay with Google is not available.
    // Please adjust to fit in with your current user flow. You are not required to explicitly
    // let the user know if isReadyToPay returns false.
    if (available) {
        mGooglePayStatusText.setVisibility(View.GONE);
        mGooglePayButton.setVisibility(View.VISIBLE);
    } else {
        mGooglePayStatusText.setText(R.string.googlepay_status_unavailable);
    }
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
        case LOAD_PAYMENT_DATA_REQUEST_CODE:
            switch (resultCode) {
                case Activity.RESULT_OK:
                    PaymentData paymentData = PaymentData.getFromIntent(data);
                    handlePaymentSuccess(paymentData);
                    System.out.println("....data...."+paymentData);
                    break;
                case Activity.RESULT_CANCELED:
                    // Nothing to here normally - the user simply cancelled without selecting a
                    // payment method.
                    break;
                case AutoResolveHelper.RESULT_ERROR:
                    Status status = AutoResolveHelper.getStatusFromIntent(data);
                    handleError(status.getStatusCode());
                    break;
            }

            // Re-enables the Pay with Google button.
            mGooglePayButton.setClickable(true);
            break;
    }
}

private void handlePaymentSuccess(PaymentData paymentData) {
    // PaymentMethodToken contains the payment information, as well as any additional
    // requested information, such as billing and shipping address.
    //
    // Refer to your processor's documentation on how to proceed from here.
    PaymentMethodToken token = paymentData.getPaymentMethodToken();
    System.out.println("token"+token);

    // getPaymentMethodToken will only return null if PaymentMethodTokenizationParameters was
    // not set in the PaymentRequest.
    if (token != null) {
        // If the gateway is set to example, no payment information is returned - instead, the
        // token will only consist of "examplePaymentMethodToken".
        if (token.getToken().equals("examplePaymentMethodToken")) {
            AlertDialog alertDialog = new AlertDialog.Builder(this)
                    .setTitle("Warning")
                    .setMessage("Gateway name set to \"example\" - please modify " +
                            "Constants.java and replace it with your own gateway.")
                    .setPositiveButton("OK", null)
                    .create();
            alertDialog.show();
        }

        String billingName = paymentData.getCardInfo().getBillingAddress().getName();
        Toast.makeText(this, getString(R.string.payments_show_name, billingName), Toast.LENGTH_LONG).show();

        // Use token.getToken() to get the token string.
        Log.d("PaymentData", "PaymentMethodToken received");
    }
}

任何人都可以帮我解决这个问题,例如提供假卡片详细信息。

谢谢,

0 个答案:

没有答案