{"id":22441387,"url":"https://github.com/hms-core/hms-iap-serverdemo","last_synced_at":"2025-08-01T18:32:14.477Z","repository":{"id":55869238,"uuid":"267634667","full_name":"HMS-Core/hms-iap-serverdemo","owner":"HMS-Core","description":"IAP server sample encapsulates APIs of the HUAWEI IAP server. It provides many sample programs for your reference or usage. The repository contains 8 branches of java, csharp, golang, nodejs, perl, php, python and ruby demo. ","archived":false,"fork":false,"pushed_at":"2023-11-07T12:51:00.000Z","size":104,"stargazers_count":27,"open_issues_count":3,"forks_count":17,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-04-16T12:54:17.102Z","etag":null,"topics":["hms","huawei","in-app-purchases","java","pay","purchase"],"latest_commit_sha":null,"homepage":"https://developer.huawei.com/consumer/en/doc/development/HMS-Examples/iap-example-v4?ha_source=hms1","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HMS-Core.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-05-28T16:04:03.000Z","updated_at":"2024-02-03T04:51:05.000Z","dependencies_parsed_at":"2023-11-07T13:52:36.097Z","dependency_job_id":null,"html_url":"https://github.com/HMS-Core/hms-iap-serverdemo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HMS-Core%2Fhms-iap-serverdemo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HMS-Core%2Fhms-iap-serverdemo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HMS-Core%2Fhms-iap-serverdemo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HMS-Core%2Fhms-iap-serverdemo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HMS-Core","download_url":"https://codeload.github.com/HMS-Core/hms-iap-serverdemo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228397819,"owners_count":17913540,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hms","huawei","in-app-purchases","java","pay","purchase"],"created_at":"2024-12-06T02:14:20.772Z","updated_at":"2024-12-06T02:14:21.459Z","avatar_url":"https://github.com/HMS-Core.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# **iap-java-sample**\n\nEnglish | [中文](README_ZH.md)\n\n## Contents\n\n * [Introduction](#introduction)\n * [Installation](#installation)\n * [Environment Requirements](#Environment Requirements)\n * [Configuration ](#configuration )\n * [Sample Code](#Sample Code)\n * [License](#license)\n\n\n## Introduction\nJava sample code encapsulates APIs of the HUAWEI IAP server. It provides many sample programs for your reference or use.\nThe following describes packages of Java sample code.\n\n**AtDemo:** Sample code of **AccessToken**. Each method can run independently.\n**OrderService:** Sample code of **OrderService**. Each method can run independently.\n**SubscriptionService:** Sample code of **SubscriptionService**. Each method can run independently.\n**notification:** Sample code of **notification**. Each method can run independently.\n\n## Installation\nBefore using Java sample code, check whether the Java environment has been installed. \nDecompress the Java sample code package.\n\nCopy the Java sample code package in the decompressed folder to the project vendor directory in the path specified by **JAVAPATH**.\nRefresh the project and ensure that the file is successfully copied to the destination directory.\n\n## Environment Requirements\nJDK 1.8 or a later version is recommended.    \n\n## Configuration\nTo use functions provided in examples, you need to set related parameters in **AtDemo.java**, **OrderService.java**, **SubscriptionService.java**, and **AppServer.java** in the package.\n\nThe following describes parameters in **AtDemo.java**.\n**clientId:** Client ID, which is obtained from app information.\n**clientSecret:** Secret access key of an app, which is obtained from app information.\n**tokenUrl:** URL for the Huawei OAuth 2.0 service to obtain a token. Please refer to [OAuth 2.0-based Authentication](https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/open-platform-oauth-0000001053629189?ha_source=hms1).\n    \nThe following describes parameters in **notification/AppServer.java**.\n**PUBLIC_KEY:** RSA public key.\n\nAt first, the meaning of **accountFlag** should be clear. If field **accountFlag** in **InappPurchaseData** equals to **1**, the account belongs to telecom carrier (**TOBTOC_SITE_URL**); otherwise, to Huawei (**TOC_SITE_URL**).  \nFor both **OrderService** and **SubscriptionService**, you need to choose appropriate site.\n**TOC_SITE_URL:** The TOC_SITE_URL has different URLs at different sites, you should always choose the address of the nearest site to access.\n**TOBTOC_SITE_URL:** The site for telecom carrier.\n\n## Sample Code\nEach method in the Java sample calls an API of the HUAWEI IAP server.\nThe following describes methods in the Java sample.\n\n\n\n1. AtDemo: getAppAT()\n\n   You can call this method to get an app-level Access Token.\n   Code location: **src/main/java/com/example/demo/AtDemo.java**\n\n\n\n2. OrderService: verifyToken()\n\n   You can call this method to verify the purchase token in the payment result with the Huawei payment server to confirm the accuracy of the payment result.\n   The URL is **{rootUrl}/applications/purchases/tokens/verify**. The rootUrl has different URLs at different sites, you should always choose the Order service address of the nearest site to access.\n   Code location: **src/main/java/com/example/demo/OrderService.java**\n       \n\n3. OrderService: cancelledListPurchase()\n\n   You can call this method to pagination query all purchase information that has been cancelled or has a refund.\n   The URL is **{rootUrl}/applications/{apiVersion}/purchases/cancelledList**. The rootUrl has different URLs at different sites, you should always choose the Order service address of the nearest site to access.\n   Code location: **src/main/java/com/example/demo/OrderService.java**\n       \n\n4. SubscriptionService: getSubscription()\n\n   You can call this method to verify a purchased subscription product, such as to obtain the validity period and status.\n   The URL is **{rootUrl}/sub/applications/{apiVersion}/purchases/get**. The rootUrl has different URLs at different sites, you should always choose the Subscription service address of the nearest site to access.\n   Code location: **src/main/java/com/example/demo/SubscriptionService.java**\n           \n\n5. SubscriptionService: stopSubscription()\n\n   You can call this method to cancel an already subscribed product, the subscription is still valid during the validity period, and subsequent renewals will be terminated.\n   The URL is **{rootUrl}/sub/applications/{apiVersion}/purchases/stop**. The rootUrl has different URLs at different sites, you should always choose the Subscription service address of the nearest site to access.\n   Code location: **src/main/java/com/example/demo/SubscriptionService.java**\n       \n\n6. SubscriptionService: delaySubscription()\n\n   You can call this method to renew a subscription product for a customer until a specified time in the future. After success, the customer's subscription will expire at a future time.\n   The URL is **{rootUrl}/sub/applications/{apiVersion}/purchases/delay**. The rootUrl has different URLs at different sites, you should always choose the Subscription service address of the nearest site to access.\n   Code location: **src/main/java/com/example/demo/SubscriptionService.java**\n\n\n\n7. SubscriptionService: returnFeeSubscription()\n\n   You can call this method to refund the last renewal fee of a subscription product, but the subscription product is still valid during the validity period, and subsequent renewals will be performed normally.\n   The URL is **{rootUrl}/sub/applications/{apiVersion}/purchases/returnFee**. The rootUrl has different URLs at different sites, you should always choose the Subscription service address of the nearest site to access.\n   Code location: **src/main/java/com/example/demo/SubscriptionService.java**\n       \n\n8. SubscriptionService: withdrawSubscription()\n\n   You can call this method to cancel a subscription, which is equivalent to executing the returnFeeSubscription method, and immediately ending the subscription service and subsequent renewal.\n   The URL is **{rootUrl}/sub/applications/{apiVersion}/purchases/withdrawal**. The rootUrl has different URLs at different sites, you should always choose the Subscription service address of the nearest site to access.\n   Code location: **src/main/java/com/example/demo/SubscriptionService.java**\n\n9. AppServer: dealNotification()\n\n   You can call this method to handle subscription event notifications.\n   The information parameter is obtained from subscription event notification.\n   Code location: **src/main/java/com/example/demo/notification/AppServer.java**\n\n10. OrderService: confirmPurchase()\n\n    You can call this method to confirm purchase after sending out product.\n    The URL is **{rootUrl}/applications/{apiVersion}/purchases/confirm**. The rootUrl has different URLs at different sites, you should always choose the Order service address of the nearest site to access.\n    Code location: **OrderService.java**\n\n##  License\nIAP Java sample is licensed under [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhms-core%2Fhms-iap-serverdemo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhms-core%2Fhms-iap-serverdemo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhms-core%2Fhms-iap-serverdemo/lists"}