I am following the tutorial here to integrate google pay API to obtain funds for my app. So far I have successfully managed to make charging but I am finding it very hard to get the charged amount on successful transfer.
The google wallet dependency I am using is
implementation 'com.google.android.gms:play-services-wallet:15.0.1'
I want to get the charged amount in MainActivity
'sonActivityResult
as I make the request from another Fragment
. But the Intent data
has only the Email address and billing status. The only logical way I can think of is to somehow inject the charged amount manullay to Intent data
but I can't seem to find a way around.
I tried to set a parameter here but It doesn't show up in the Intent
I receive in the onActivityResult
.
Can anyone give me a hand here?
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);
}
Basically, your credit card issuer has to support Google Pay in order for you to use it. While there is no charge to send money to family and friends or buying with a debit card, Google Pay will charge 2.9 percent if you use a credit card.
Step 1: Define your Google Pay API version. Step 2: Request a payment token for your payment provider. Step 3: Define supported payment card networks. Step 4: Describe your allowed payment methods. Step 5: Create a PaymentsClient instance. Step 6: Determine readiness to pay with the Google Pay API. Step 7: Create a PaymentDataRequest object.
The linked payment instrument (such as a credit card or bank account) will be charged automatically when your accrued Google Cloud costs meet the threshold amount on your Cloud Billing account, or thirty days after your last automatic charge, whichever comes first.
After a Google user grants permission for your site to receive information about the user's selected form of payment and optional contact data, handle the response from the Google Pay API. Extract the payment token from the paymentData response.
Customer payment data is end-to-end encrypted from Google's servers to your payment processor. Google Pay works with your existing payments processing stack and can be implemented with a few lines of code. 7x increase in the number of unique users paying with Google Pay.
Note that the retrieval of the payment token does not imply that a payment transaction happened successfully. This is something that only happens when you submit your order for processing through your payment processor or gateway. When that happens, this typically includes an order id and final charged amount.
I'd suggest this as a more specific way to account for successful transactions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With