android - Google Pay API 获取扣款金额

标签 android google-pay

我正在学习教程 here集成谷歌支付 API 以获得我的应用程序的资金。到目前为止,我已经成功地进行了收费,但我发现很难在成功转帐时获得收费金额。

我使用的谷歌钱包依赖是

implementation 'com.google.android.gms:play-services-wallet:15.0.1'

当我从另一个 Fragment 发出请求时,我想在 MainActivityonActivityResult 中获取收费金额。但是 Intent 数据 只有电子邮件地址和账单状态。我能想到的唯一合乎逻辑的方法是以某种方式将收费金额 manullay 注入(inject) Intent data 但我似乎找不到解决方法。

我试图在这里设置一个参数,但它没有出现在我在 onActivityResult 中收到的 Intent 中。

有人可以帮我吗?

public void requestPayment(BigDecimal amount) {
        // Disables the button to prevent multiple clicks.
        //mGooglePayButton.setClickable(false);

        // The price provided to the API should include taxes and shipping.
        // This price is not displayed to the user.

        String chargeAmount = amount.divide(MICROS).setScale(2, RoundingMode.HALF_EVEN).toString();

//        String price = PaymentsUtil.microsToString(chargeAmount);

        TransactionInfo transaction = PaymentsUtil.createTransaction(chargeAmount);

        Parcel parcel = Parcel.obtain();
        parcel.writeString(chargeAmount);
        parcel.recycle();
        transaction.writeToParcel(parcel, 0);

        PaymentDataRequest request = PaymentsUtil.createPaymentDataRequest(transaction);

        Task<PaymentData> futurePaymentData = mPaymentsClient.loadPaymentData(request);


        // Since loadPaymentData may show the UI asking the user to select a payment method, we use
        // AutoResolveHelper to wait for the user interacting with it. Once completed,
        // onActivityResult will be called with the result.
        AutoResolveHelper.resolveTask(futurePaymentData, Objects.requireNonNull(getActivity()), LOAD_PAYMENT_DATA_REQUEST_CODE);


    }

最佳答案

请注意,检索到支付 token 并不意味着支付交易成功。只有当您通过支付处理器或网关提交订单进行处理时,才会发生这种情况。发生这种情况时,这通常包括订单 ID 和最终收费金额。

我建议将此作为一种更具体的方式来说明成功的交易。

关于android - Google Pay API 获取扣款金额,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51104035/

相关文章:

java - 如何在应用程序订阅android中使用按比例分配模式

android - 从我的 Android 应用调用 Google Pay Intent 时出现错误 "You have exceeded the maximum transaction amount set by your bank"

java - 如何在 Cmake for Android 中导入共享库

android - 将对象保存到 bandle 时出错

android - CheckedTextView 未选中

android - 生成的 ListView 应用程序的 Intent 停止工作

javascript - 如何在 Android 的 React Native 中以编程方式打开 Tez 应用程序(印度的 Google Pay 应用程序)?

android - 如何为 Ionic 4 (android/ios) 应用程序创建 google pay?

java - 构建应用程序时运行单元测试 (Android)