diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..db8e105 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,16 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + "program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/csharp.dll", + "args": [], + "cwd": "${workspaceFolder}", + "stopAtEntry": false, + "console": "internalConsole" + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..360d427 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,20 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "shell", + "args": [ + "build", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "group": "build", + "presentation": { + "reveal": "silent" + }, + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/Demo.cs b/Demo.cs new file mode 100644 index 0000000..e294455 --- /dev/null +++ b/Demo.cs @@ -0,0 +1,449 @@ +/* + * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +using System; +using System.Collections.Generic; +using System.IO; +using System.Net; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Security.Cryptography; +using System.Text; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace IapDemo +{ + + public class DemoConfig + { + public String clientSecret { get; set; } + public String clientId { get; set; } + public String tokenUrl { get; set; } + + public String orderUrl { get; set; } + + public String subscriptionUrl { get; set; } + + public String applicationPublicKey { get; set; } + + public static DemoConfig getDefaultConfig() + { + DemoConfig demoConfig = new DemoConfig(); + // your client secret + demoConfig.clientSecret = "appsecret"; + // your app id + demoConfig.clientId = "1234567"; + + // application public key, base64 encode + demoConfig.applicationPublicKey = "public key, base64 encode"; + + // product token url + // demoConfig.tokenUrl = "https://oauth-login.cloud.huawei.com/oauth2/v3/token"; + + demoConfig.tokenUrl = "http://exampleserver/_mockserver_/oauth2/v3/token"; + + + return demoConfig; + } + } + + public class AtResponse + { + public string access_token { get; set; } + } + + + public class AtDemo + { + public static String getAppAt() + { + var demoConfig = DemoConfig.getDefaultConfig(); + + String grant_type = "client_credentials"; + String msgBody = String.Format("grant_type={0}&client_secret={1}&client_id={2}", WebUtility.UrlEncode(grant_type), + WebUtility.UrlEncode(demoConfig.clientSecret), WebUtility.UrlEncode(demoConfig.clientId)); + + String retString = httpPost(demoConfig.tokenUrl, "application/x-www-form-urlencoded", msgBody, 5, null); + + if (retString.IndexOf("access_token") != -1) + { + var atResponse = JsonSerializer.Deserialize(retString); + return atResponse.access_token; + } + else + { + System.Console.Error.WriteLine("Get token fail, " + retString); + throw new System.ArgumentException("Get token fail", retString); + } + } + + public static String httpPost(String httpUrl, String contentType, String requestBody, int timeOut, HttpRequestHeaders headers) + { + var client = new HttpClient(); + client.Timeout = TimeSpan.FromSeconds(timeOut); + + if (headers != null) + { + foreach (var header in headers) + { + client.DefaultRequestHeaders.Add(header.Key, header.Value); + } + } + + var httpContent = new StringContent(requestBody, Encoding.UTF8, contentType); + + var repTask = client.PostAsync(httpUrl, httpContent); + repTask.Wait(); + var resContent = repTask.Result.Content; + var strTask = resContent.ReadAsStringAsync(); + strTask.Wait(); + var retString = strTask.Result; + return retString; + } + + + public static HttpRequestHeaders buildAuthorization() + { + var appAt = AtDemo.getAppAt(); + var oriString = String.Format("APPAT:{0}", appAt); + var authString = Convert.ToBase64String(Encoding.UTF8.GetBytes(oriString)); + var authHeaderString = String.Format("Basic {0}", authString); + HttpRequestHeaders headers = new HttpClient().DefaultRequestHeaders; + headers.Add(HttpRequestHeader.Authorization.ToString(), authHeaderString); + return headers; + } + + public static Boolean verifyRsaSign(String content, String sign, String publicKey) + { + bool checkRet = false; + using (var rsaProv = new RSACryptoServiceProvider()) + { + byte[] contentBytes = Encoding.UTF8.GetBytes(content); + byte[] signBytes = Convert.FromBase64String(sign); + byte[] publicKeyBytes = Convert.FromBase64String(publicKey); + try + { + int readBytes = 0; + rsaProv.ImportSubjectPublicKeyInfo(publicKeyBytes, out readBytes); + checkRet = rsaProv.VerifyData(contentBytes, signBytes, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1); + } + catch (CryptographicException e) + { + Console.WriteLine(e.Message); + } + finally + { + rsaProv.PersistKeyInCsp = false; + } + } + return checkRet; + } + } + + public class OrderDemo + { + public static String getRootUrl(int accountFlag) { + if (accountFlag == 1) { + // site for telecom carrier + return "https://orders-at-dre.iap.dbankcloud.com"; + } + // TODO: replace the (ip:port) to the real one, + return "http://ip:port"; + } + public static void verifyToken(String purchaseToken, String productId,int accountFlag) + { + var requestHeaders = AtDemo.buildAuthorization(); + Dictionary bodyMap = new Dictionary(); + bodyMap.Add("purchaseToken", purchaseToken); + bodyMap.Add("productId", productId); + var bodyString = JsonSerializer.Serialize(bodyMap); + String responseString = AtDemo.httpPost(getRootUrl(accountFlag) + "/applications/purchases/tokens/verify", "application/json", bodyString, 5, requestHeaders); + + // TODO: display the response as string in console, you can replace it with your business logic. + Console.WriteLine(responseString); + } + + public static void cancelledListPurchase(long endAt, long startAt, int maxRows, int type, string continuationToken,int accountFlag) + { + var requestHeaders = AtDemo.buildAuthorization(); + + // pack the request body + Dictionary bodyMap = new Dictionary(); + bodyMap.Add("endAt", endAt.ToString()); + bodyMap.Add("startAt", startAt.ToString()); + bodyMap.Add("maxRows", maxRows.ToString()); + bodyMap.Add("type", type.ToString()); + bodyMap.Add("continuationToken", continuationToken.ToString()); + var bodyString = JsonSerializer.Serialize(bodyMap); + + String responseString = AtDemo.httpPost(getRootUrl(accountFlag) + "/applications/v2/purchases/cancelledList", "application/json", bodyString, 5, requestHeaders); + + // TODO: display the response as string in console, you can replace it with your business logic. + Console.WriteLine(responseString); + } + + public static void confirmPurchase(String purchaseToken, String productId,int accountFlag) + { + var requestHeaders = AtDemo.buildAuthorization(); + + // pack the request body + Dictionary bodyMap = new Dictionary(); + bodyMap.Add("purchaseToken", purchaseToken); + bodyMap.Add("productId", productId); + + var bodyString = JsonSerializer.Serialize(bodyMap); + + String responseString = AtDemo.httpPost(getRootUrl(accountFlag) + "/applications/v2/purchases/confirm", "application/json", bodyString, 5, requestHeaders); + + // TODO: display the response as string in console, you can replace it with your business logic. + Console.WriteLine(responseString); + } + } + + public class SubscriptionDemo + { + + public static String getRootUrl(int accountFlag) { + if ( accountFlag == 1) { + // site for telecom carrier + return "https://subscr-at-dre.iap.dbankcloud.com"; + } + // TODO: replace the (ip:port) to the real one, + return "http://ip:port"; + } + public static void getSubscription(string subscriptionId, string purchaseToken,int accountFlag) + { + var headers = AtDemo.buildAuthorization(); + + // pack the request body + Dictionary bodyMap = new Dictionary(); + bodyMap.Add("subscriptionId", subscriptionId); + bodyMap.Add("purchaseToken", purchaseToken); + + var bodyString = JsonSerializer.Serialize(bodyMap); + var config = DemoConfig.getDefaultConfig(); + + String responseString = AtDemo.httpPost(getRootUrl(accountFlag) + "/sub/applications/v2/purchases/get", + "application/json", bodyString, 5, headers); + + // TODO: display the response as string in console, you can replace it with your business logic. + Console.WriteLine(responseString); + } + + public static void stopSubscription(string subscriptionId, string purchaseToken,int accountFlag) + { + var headers = AtDemo.buildAuthorization(); + + // pack the request body + Dictionary bodyMap = new Dictionary(); + bodyMap.Add("subscriptionId", subscriptionId); + bodyMap.Add("purchaseToken", purchaseToken); + + var bodyString = JsonSerializer.Serialize(bodyMap); + + String responseString = AtDemo.httpPost(getRootUrl(accountFlag) + "/sub/applications/v2/purchases/stop", + "application/json", bodyString, 5, headers); + + // TODO: display the response as string in console, you can replace it with your business logic. + Console.WriteLine(responseString); + } + + public static void delaySubscription(string subscriptionId, string purchaseToken, long currentExpirationTime, + long desiredExpirationTime,int accountFlag) + { + var headers = AtDemo.buildAuthorization(); + + // pack the request body + Dictionary bodyMap = new Dictionary(); + bodyMap.Add("subscriptionId", subscriptionId); + bodyMap.Add("purchaseToken", purchaseToken); + bodyMap.Add("currentExpirationTime", currentExpirationTime + ""); + bodyMap.Add("desiredExpirationTime", desiredExpirationTime + ""); + var bodyString = JsonSerializer.Serialize(bodyMap); + + String responseString = AtDemo.httpPost(getRootUrl(accountFlag) + "/sub/applications/v2/purchases/delay", + "application/json", bodyString, 5, headers); + + // TODO: display the response as string in console, you can replace it with your business logic. + Console.WriteLine(responseString); + } + + public static void returnFeeSubscription(string subscriptionId, string purchaseToken,int accountFlag) + { + var headers = AtDemo.buildAuthorization(); + + // pack the request body + Dictionary bodyMap = new Dictionary(); + bodyMap.Add("subscriptionId", subscriptionId); + bodyMap.Add("purchaseToken", purchaseToken); + + var bodyString = JsonSerializer.Serialize(bodyMap); + + String responseString = AtDemo.httpPost(getRootUrl(accountFlag) + "/sub/applications/v2/purchases/returnFee", + "application/json", bodyString, 5, headers); + + // TODO: display the response as string in console, you can replace it with your business logic. + Console.WriteLine(responseString); + } + + public static void withdrawalSubscription(string subscriptionId, string purchaseToken,int accountFlag) + { + var headers = AtDemo.buildAuthorization(); + + // pack the request body + Dictionary bodyMap = new Dictionary(); + bodyMap.Add("subscriptionId", subscriptionId); + bodyMap.Add("purchaseToken", purchaseToken); + + var bodyString = JsonSerializer.Serialize(bodyMap); + + String responseString = AtDemo.httpPost(getRootUrl(accountFlag) + "/sub/applications/v2/purchases/withdrawal", + "application/json", bodyString, 5, headers); + + // TODO: display the response as string in console, you can replace it with your business logic. + Console.WriteLine(responseString); + } + + } + + public class NotificationRequest + { + public string statusUpdateNotification { get; set; } + public string notifycationSignature { get; set; } + } + + public class NotificationResponse + { + public string ErrorCode { get; set; } + public string ErrorMsg { get; set; } + } + + public class StatusUpdateNotification + { + public string environment { get; set; } + public int notificationType { get; set; } + public string subscriptionId { get; set; } + public long cancellationDate { get; set; } + public string orderId { get; set; } + public string latestReceipt { get; set; } + public string latestReceiptInfo { get; set; } + public string latestReceiptInfoSignature { get; set; } + public string latestExpiredReceipt { get; set; } + public string latestExpiredReceiptInfo { get; set; } + public string latestExpiredReceiptInfoSignature { get; set; } + public long autoRenewStatus { get; set; } + public string refundPayOrderId { get; set; } + public string productId { get; set; } + public string applicationId { get; set; } + public int expirationIntent { get; set; } + } + + enum NotificationType : int + { + INITIAL_BUY = 0, + CANCEL = 1, + RENEWAL = 2, + INTERACTIVE_RENEWAL = 3, + NEW_RENEWAL_PREF = 4, + RENEWAL_STOPPED = 5, + RENEWAL_RESTORED = 6, + RENEWAL_RECURRING = 7, + ON_HOLD = 9, + PAUSED = 10, + PAUSE_PLAN_CHANGED = 11, + PRICE_CHANGE_CONFIRMED = 12, + DEFERRED = 13, + } + + public class NotificationDemo + { + public static void dealNotification(String information) + { + var request = JsonSerializer.Deserialize(information); + var checkRet = AtDemo.verifyRsaSign(request.statusUpdateNotification, request.notifycationSignature, DemoConfig.getDefaultConfig().applicationPublicKey); + if (!checkRet) + { + Console.WriteLine("rsa sign check fail"); + return; + } + + var info = JsonSerializer.Deserialize(request.statusUpdateNotification); + var notificationType = (NotificationType)info.notificationType; + switch (notificationType) + { + case NotificationType.INITIAL_BUY: + break; + case NotificationType.CANCEL: + break; + case NotificationType.RENEWAL: + break; + case NotificationType.INTERACTIVE_RENEWAL: + break; + case NotificationType.NEW_RENEWAL_PREF: + break; + case NotificationType.RENEWAL_STOPPED: + break; + case NotificationType.RENEWAL_RESTORED: + break; + case NotificationType.RENEWAL_RECURRING: + break; + case NotificationType.ON_HOLD: + break; + case NotificationType.PAUSED: + break; + case NotificationType.PAUSE_PLAN_CHANGED: + break; + case NotificationType.PRICE_CHANGE_CONFIRMED: + break; + case NotificationType.DEFERRED: + break; + default: + break; + } + } + } + + + + public class Demo + { + + static void Main(string[] args) + { + var at = AtDemo.getAppAt(); + Console.Out.WriteLine(at); + + OrderDemo.verifyToken("demoToken", "demoProductId", 0); + + OrderDemo.cancelledListPurchase(123, 456, 100, 0, "demoToken", 0); + + OrderDemo.confirmPurchase("demoToken", "demoProductId", 0); + + SubscriptionDemo.getSubscription("demoId", "demoToken", 0); + + SubscriptionDemo.stopSubscription("demoId", "demoToken", 0); + + SubscriptionDemo.delaySubscription("demoId", "demoToken", 123, 456, 0); + + SubscriptionDemo.returnFeeSubscription("demoId", "demoToken", 0); + + SubscriptionDemo.withdrawalSubscription("demoId", "demoToken", 0); + } + } + +} diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..490b5c7 --- /dev/null +++ b/LICENSE @@ -0,0 +1,53 @@ +Apache License + +Version 2.0, January 2004 + +http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. + +"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: + +You must give any other recipients of the Work or Derivative Works a copy of this License; and +You must cause any modified files to carry prominent notices stating that You changed the files; and +You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and +If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. + +You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. +5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..9cef658 --- /dev/null +++ b/README.md @@ -0,0 +1,88 @@ +## iap-csharp-sample + +## Introduction + IAP csharp sample encapsulates APIs of the HUAWEI IAP server. It provides many sample programs for your reference or usage. + The following describes packages of java sample code. + + DemoConfig: Sample code of config. + AtDemo: Sample code of AccessToken. + OrderDemo: Sample code of OrderService. + SubscriptionDemo: Sample code of SubscriptionDemo. + NotificationDemo: Sample code of notification. + + +## Configuration + To use functions provided in examples, you need to set related parameters in Demo.cs. + + The following describes parameters in class DemoConfig. + clientId: Client ID, which is obtained from app information. + clientSecret: Secret access key of an app, which is obtained from app information. + tokenUrl: URL for the Huawei OAuth 2.0 service to obtain a token, please refer to Generating an App-Level Access Token. + applicationPublicKey: Application RSA publick key, base64 encode string. + + At 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). + For both OrderService and SubscriptionService, you need to choose appropriate site. + 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. + TOBTOC_SITE_URL: The site for telecom carrier. + +## Example Code + Each method in the sample calls an API of the HUAWEI IAP server. + The following describes methods in the sample. + + 1). AtDemo: getAppAT() + You can call this method to get App Level AccessToken. + Code location: Demo.cs AtDemo.getAppAt + + 2). OrderDemo: verifyToken() + 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. + The URL is {orderUrl}/applications/purchases/tokens/verify. The orderUrl has different urls at different sites, you should always choose the Order service address of the nearest site to access. + Code location: Demo.cs OrderDemo.verifyToken + + 3). OrderDemo: cancelledListPurchase() + You can call this method to pagination query all purchase information that has been cancelled or has a refund. + The URL is {orderUrl}/applications/{apiVersion}/purchases/cancelledList. The orderUrl has different urls at different sites, you should always choose the Order service address of the nearest site to access. + Code location: Demo.cs OrderDemo.cancelledListPurchase + + 4). SubscriptionDemo: getSubscription() + You can call this method to verify a purchased subscription product, such as to obtain the validity period and status。 + The URL is {subscriptionUrl}/sub/applications/{apiVersion}/purchases/get. The subscriptionUrl has different urls at different sites, you should always choose the Subscription service address of the nearest site to access. + Code location Demo.cs SubscriptionDemo.getSubscription + + 5). SubscriptionDemo: stopSubscription() + 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. + The URL is {subscriptionUrl}/sub/applications/{apiVersion}/purchases/stop. The subscriptionUrl has different urls at different sites, you should always choose the Subscription service address of the nearest site to access. + Code location Demo.cs SubscriptionDemo.stopSubscription + + 6). SubscriptionDemo: delaySubscription() + 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. + The URL is {subscriptionUrl}/sub/applications/{apiVersion}/purchases/delay. The subscriptionUrl has different urls at different sites, you should always choose the Subscription service address of the nearest site to access. + Code location Demo.cs SubscriptionDemo.delaySubscription + + 7). SubscriptionDemo: returnFeeSubscription() + 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. + The URL is {subscriptionUrl}/sub/applications/{apiVersion}/purchases/returnFee. The subscriptionUrl has different urls at different sites, you should always choose the Subscription service address of the nearest site to access. + Code location Demo.cs SubscriptionDemo.returnFeeSubscription + + 8). SubscriptionDemo: withdrawalSubscription() + 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. + The URL is {subscriptionUrl}/sub/applications/{apiVersion}/purchases/withdrawal. The subscriptionUrl has different urls at different sites, you should always choose the Subscription service address of the nearest site to access. + Code location Demo.cs SubscriptionDemo.withdrawalSubscription + + 9). NotificationDemo: dealNotification() + You can call this method to handle subscription event notifications. + The information parameter is obtained from subscription event notification. + Code location Demo.cs NotificationDemo.dealNotification() + + 10). OrderService: confirmPurchase() + You can call this method to confirm purchase after sending out product. + 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. + Code location Demo.cs OrderDemo.confirmPurchase + + + + +## License + IAP csharp sample is licensed under the [Apache License, version 2.0](http://www.apache.org/licenses/LICENSE-2.0). + + diff --git a/csharp.csproj b/csharp.csproj new file mode 100644 index 0000000..1b6c1c1 --- /dev/null +++ b/csharp.csproj @@ -0,0 +1,23 @@ + + + + Exe + netcoreapp3.1 + + +