Initial integration of Google Pay and integration of googlepay

Source: Internet
Author: User

Initial integration of Google Pay and integration of googlepay
Preparation: the account of the Google Play Console is located in the vpn (which is explained below) in the United States or Hong Kong (the reason is described below) and operated on a mobile phone project with the Google Play application market.

First, the GoogleSample project contains an example about google pay in android-play-billing, which can be used for reference, (only the Application ID of the apk you created on the google play console must be used for registration)

In New under the main directoryCopy the package name directory in the com. android. vending. billing path, as shown in.Copy the IInAppBillingService. aidl file to the file address in this directory. Copy the util directory in the trivialDrive directory of android-play-billing to the directory address in your project. To obtain the in-app payment, you must also apply for the permission.Add under AndroidManifest. xml The permission is still in Write tags in AndroidManifest. xml Android: name = "com. google. android. gms. wallet. api. enabled"
Android: value = "true"/> and then build. gradle dependency under the module Directory Com. google. android. gms: play-services-wallet: 11.8.0
64 K warning may occur when the project uses the rx series retrofit series and relies heavily on google services.
Code Writing

Writing code is actually very simple. Just copy and paste it with google's tutorial.

Create an IabHelper instance 'abhelper mHelper;

@Override
public void onCreate(Bundle savedInstanceState) {
// …
String base64EncodedPublicKey;

// Compute your public key and store it in base64EncodedPublicKey
MHelper = new IabHelper (this, base64EncodedPublicKey );
}Here base64EncodedPublicKey refers to the apk key created in the google play console (which is explained below)

Start Service ListeningmHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
if (!result.isSuccess()) {
// Oh no, there was a problem.
Log.d(TAG, "Problem setting up In-app Billing: " + result);
}
// Hooray, IAB is fully set up!
}
});

Disconnect and release the listener when exiting the interface@Override
public void onDestroy() {
super.onDestroy();
if (mHelper != null) mHelper.dispose();
mHelper = null;
}

Payment Procedure/**
* @ Param act activity
* @ Param sku: The product id of the product created in the Application
* @ Param requestCode onActivityResult
* @ Param listener: Payment listener
* @ Param extraData: An empty string can be passed for parameters.
*/
// Purchase items
MHelper. launchPurchaseFlow (this, SKU GOOGLE_PAY_RESULT,
MPurchaseFinishedListener, "bGoa + V7g/yqDXvKRqq + JTFn4uQZbPiQJo4pf9RzJ ");IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener
= new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase purchase)
{
if (result.isFailure()) {
Log.d(TAG, "Error purchasing: " + result);
return;
}
else if (purchase.getSku().equals(SKU_GAS)) {
// consume the gas and update the UI
}
else if (purchase.getSku().equals(SKU_PREMIUM)) {
// give user access to premium content and update the UI
}
}
};

Callback Processingoverride fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (requestCode == GOOGLE_PAY_RESULT) {
mHelper!!.handleActivityResult(requestCode, resultCode, data)
...
}
}

Here, the basic integration of the Code is complete. Here, it is only a one-time purchase for the integrated application, if you want to integrate consumption, purchase or subscribe to the service, please refer to the official documentation address. If you click the payment dialog box that appears, the code is correct. The failure is only because of some errors in the console.

Console

In fact, this part is based on the reference documentation, but you only need to pay attention to a few pitfalls.

The consumed key can be found in the service and api. Note that to delete spaces, you must test that the payment application must be published. Therefore, no matter which step your project writes, you only need to release it, but do not release the official version. We recommend that you release the alpha version before releasing it.Application classification,Pricing, distribution content, and other columns ensure that no warning is given in the distribution content. Be sure not to select China, Laos, or other countries (as long as there is a question mark next to the country, do not select, because google pay is not supported in these countries !) After the product is successfully released, you can create an in-app product.

Click Version Management> application version management alpha version to create a tester, note: The account currently logged in cannot be directly tested. After being successfully created, you must click the test link below and agree to become a tester. finished console Integration

Testing takes 1 to 2 hours to wait until your application displaysPublished


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.