Google Pay Card Payments - Android Custom Integration
Know how to integrate Cards on Google Pay on your Razorpay Custom Integration.
Using this feature, you can allow your customers to make payments on your Android app using the cards they have saved on Google Pay.
To support Google Pay Cards on your custom checkout implementation:
- .
- Trigger payment when the user clicks Google Pay Cards on your checkout.
- You should have already integrated on your Android app.
- Complete the onboarding process mentioned .
- .
- .
- .
- .
- .
- .
- .
- .
You will need to integrate the Google SDK in your Android app.
Import the SDK from our Maven repository by adding the following lines to your app's build.gradle file.
repositories {mavenCentral()}dependencies {implementation 'com.razorpay:gpay:1.0.0'}
Google Pay Cards is supported on Razorpay Android - Custom Checkout version 3.8.8 and higher. If you are using an older version, you will need to update the same.
You can update the Custom Checkout version in your build.gradle file as shown below:
dependencies {...implementation(name:'razorpay-android-3.8.8', ext: 'aar')’)}
Add the following lines to your app's build.gradle file.
dependencies {...implementation 'com.android.support:customtabs:26.1.0'implementation 'com.google.android.gms:play-services-tasks:15.0.1'implementation 'com.google.android.gms:play-services-wallet:18.0.0'...}
Add the following lines inside the app’s AndroidManifest.xml file.
<meta-dataandroid:name="com.google.android.gms.wallet.api.enabled"android:value="true" />
To instantiate Razorpay, pass a reference of your activity to the Razorpay constructor, as shown below:
import com.razorpay.RazorpayRazorpay razorpay = new Razorpay(activity);
Add your Razorpay API keys to AndroidManifest.xml.
Handy Tips
API keys should not be hardcoded in the app. It should be sent from your server-side as an app-related metadata fetch.
The sample AndroidManifest.xml file with auto-OTP reading feature enabled is shown below:
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"><application><meta-dataandroid:name="com.razorpay.ApiKey"android:value="YOUR_KEY_ID"/></application></manifest>
To set your API key programmatically, that is, at the runtime instead of statically defining it in your AndroidManifest.xml, you can pass it as a parameter to the Razorpay constructor, as shown below:
Razorpay razorpay = new Razorpay(activity, "YOUR_KEY_ID");
Order is an important step in the payment process.
- An order should be created for every payment.
- You can create an order using the . It is a server-side API call. Know how to Orders API.
- The order_id received in the response should be passed to the checkout. This ties the Order with the payment and secures the request from being tampered.
Here is the list of parameters and their description for creating an order:
amount
mandatory
integer Payment amount in the smallest currency sub-unit. For example, if the amount to be charged is $299.00, then pass 29900 in this field. In the case of three decimal currencies, such as KWD, BHD and OMR, to accept a payment of 295.991, pass the value as 295990. And in the case of zero decimal currencies such as JPY, to accept a payment of 295, pass the value as 295.
Watch Out!
As per payment guidelines, you should pass the last decimal number as 0 for three decimal currency payments. For example, if you want to charge a customer 99.991 KD for a transaction, you should pass the value for the amount parameter as 99990 and not 99991.
receipt
optional
string Your receipt id for this order should be passed here. Maximum length is 40 characters.
notes
optional
json object Key-value pair that can be used to store additional information about the entity. Maximum 15 key-value pairs, 256 characters (maximum) each. For example, "note_key": "Beam me up Scotty”.
partial_payment
optional
boolean Indicates whether the customer can make a partial payment. Possible values:
true: The customer can make partial payments.false(default): The customer cannot make partial payments.
id
mandatory
string Unique identifier of the customer. For example, cust_1Aa00000000004.
Know more about
.Descriptions for the response parameters are present in the
table.The error response parameters are available in the
.The razorpay_order_id, returned on successful creation of the order, should be sent to the Checkout form.
To get a list of available payment methods, call getPaymentMethods. This fetches the list of payment methods asynchronously and returns the result in JSON format in the onPaymentMethodsReceived callback. For the structure of the JSON result, you can refer:
razorpay.getPaymentMethods(new Razorpay.PaymentMethodsCallback() {@Overridepublic void onPaymentMethodsReceived(String result) {JSONObject paymentMethods = new JSONObject(result);}@Overridepublic void onError(String error){}});});
Know
using Razorpay Android Custom SDK in detail.Handy Tips
Ensure the Google Pay Cards feature is enabled for your account. If it is not enabled,
with us to get it enabled on your account.Use the code given below to check if Google Pay cards are setup on your customer’s device.
razorpay.isUserRegisteredOnGpay(this, new GPayCardsRegisteredListener(){@Overridepublic void isUserRegisteredOnGpay(boolean status){//status of user}}
You should show Google Pay cards method to your customers only when isUserRegisteredOnGpay returns true.
The bank ACS pages are displayed to the user in a WebView.
You need to define a WebView in your layout and pass the reference to our SDK using setWebView, as shown below:
webview = findViewById(R.id.payment_webview);// Hide the WebView until the payment details are submittedwebview.setVisibility(View.GONE);razorpay.setWebView(webview);
Once you have received the customer's payment information, it needs to be sent to Razorpay to complete the creation step of the payment flow. You can do this by invoking the submit method. Before invoking this method, you have to make your WebView visible to the customer. The data that needs to be submitted in the form of a JSONObject is shown below:
try {JSONObject data = new JSONObject();data.put("amount", 1000); // pass in currency subunits. For example, paise. Amount: 1000 equals ₹10data.put("order_id", "order_DgZ26rHjbzLLY2");//sample order_id. Generate orders using Orders APIdata.put("email", "gaurav.kumar@example.com");data.put("contact", "9876543210");JSONObject notes = new JSONObject();notes.put("custom_field", "abc");data.put("notes", notes);data.put("provider", "google_pay");// Make WebView visible before submitting payment detailswebview.setVisibility(View.VISIBLE);razorpay.submit(data, new PaymentResultListener() {@Overridepublic void onPaymentSuccess(String razorpayPaymentId) {// Razorpay payment ID is passed here after a successful payment}@Overridepublic void onPaymentError(int code, String description) {// Error code and description is passed here}});} catch (Exception e) {Log.e(TAG, "Error in submitting payment details", e);}
Handy Tips
To reuse the Razorpay Checkout web integration inside a web view on Android or iOS, pass a
along with other checkout options to process the desired payment.You have the option to implement PaymentResultListener or PaymentResultWithDataListener to receive callbacks for the payment result.
PaymentResultListener provides only payment_id as the payment result.
PaymentResultWithDataListener provides additional payment data, such as email and contact of the customer, along with the order_id, payment_id, signature and more.
razorpay.submit(data, new PaymentResultWithDataListener() {@Overridepublic void onPaymentSuccess(String razorpayPaymentId, PaymentData paymentData) {// Razorpay payment ID and PaymentData passed here after a successful payment}@Overridepublic void onPaymentError(int code, String description) {// Error code and description is passed here}});} catch (Exception e) {Log.e(TAG, "Error in submitting payment details", e);}
A successful payment returns the following fields to the Checkout form.
- You need to store these fields in your server.
- You can confirm the authenticity of these details by verifying the signature in the next step.
razorpay_payment_id
string Unique identifier for the payment returned by Checkout only for successful payments.
razorpay_order_id
string Unique identifier for the order returned by Checkout.
razorpay_signature
string Signature returned by the Checkout. This is used to verify the payment.
This is a mandatory step to confirm the authenticity of the details returned to the Checkout form for successful payments.
-
Create a signature in your server using the following attributes:
order_id: Retrieve theorder_idfrom your server. Do not use therazorpay_order_idreturned by Checkout.razorpay_payment_id: Returned by Checkout.key_secret: Available in your server. Thekey_secretthat was generated from the .
-
Use the SHA256 algorithm, the
razorpay_payment_idand theorder_idto construct a HMAC hex digest as shown below:generated_signature = hmac_sha256(order_id + "|" + razorpay_payment_id, secret);if (generated_signature == razorpay_signature) {payment is successful} -
If the signature you generate on your server matches the
razorpay_signaturereturned to you by the Checkout form, the payment received is from an authentic source.
Given below is the sample code for payment signature verification:
RazorpayClient razorpay = new RazorpayClient("[YOUR_KEY_ID]", "[YOUR_KEY_SECRET]");String secret = "EnLs21M47BllR3X8PSFtjtbd";JSONObject options = new JSONObject();options.put("razorpay_order_id", "order_IEIaMR65cu6nz3");options.put("razorpay_payment_id", "pay_IH4NVgf4Dreq1l");options.put("razorpay_signature", "0d4e745a1838664ad6c9c9902212a32d627d68e917290b0ad5f08ff4561bc50f");boolean status = Utils.verifyPaymentSignature(options, secret);
After you have completed the integration, you can
, make test payments, replace the test key with the live key and integrate with other .Is this integration guide useful?
ON THIS PAGE