├── .gitignore ├── .travis.yml ├── .vscode ├── settings.json └── tasks.json ├── LICENSE ├── README.md ├── android └── inappbilling │ ├── .gitignore │ ├── .idea │ ├── .name │ ├── compiler.xml │ ├── copyright │ │ └── profiles_settings.xml │ ├── encodings.xml │ ├── gradle.xml │ ├── misc.xml │ ├── modules.xml │ └── runConfigurations.xml │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── inappbillinghelper │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── aidl │ │ └── com │ │ │ └── android │ │ │ └── vending │ │ │ └── billing │ │ │ └── IInAppBillingService.aidl │ │ └── java │ │ └── com │ │ └── tangrainc │ │ └── inappbilling │ │ └── InAppBillingHelper.java │ ├── projectFilesBackup │ └── .idea │ │ └── workspace.xml │ └── settings.gradle ├── demo ├── .vscode │ ├── launch.json │ └── settings.json ├── app │ ├── App_Resources │ │ ├── Android │ │ │ ├── AndroidManifest.xml │ │ │ ├── app.gradle │ │ │ ├── drawable-hdpi │ │ │ │ ├── background.png │ │ │ │ ├── icon.png │ │ │ │ └── logo.png │ │ │ ├── drawable-ldpi │ │ │ │ ├── background.png │ │ │ │ ├── icon.png │ │ │ │ └── logo.png │ │ │ ├── drawable-mdpi │ │ │ │ ├── background.png │ │ │ │ ├── icon.png │ │ │ │ └── logo.png │ │ │ ├── drawable-nodpi │ │ │ │ └── splash_screen.xml │ │ │ ├── drawable-xhdpi │ │ │ │ ├── background.png │ │ │ │ ├── icon.png │ │ │ │ └── logo.png │ │ │ ├── drawable-xxhdpi │ │ │ │ ├── background.png │ │ │ │ ├── icon.png │ │ │ │ └── logo.png │ │ │ ├── drawable-xxxhdpi │ │ │ │ ├── background.png │ │ │ │ ├── icon.png │ │ │ │ └── logo.png │ │ │ ├── values-v21 │ │ │ │ ├── colors.xml │ │ │ │ └── styles.xml │ │ │ └── values │ │ │ │ ├── colors.xml │ │ │ │ └── styles.xml │ │ └── iOS │ │ │ ├── Assets.xcassets │ │ │ ├── AppIcon.appiconset │ │ │ │ ├── Contents.json │ │ │ │ ├── icon-29.png │ │ │ │ ├── icon-29@2x.png │ │ │ │ ├── icon-29@3x.png │ │ │ │ ├── icon-40.png │ │ │ │ ├── icon-40@2x.png │ │ │ │ ├── icon-40@3x.png │ │ │ │ ├── icon-50.png │ │ │ │ ├── icon-50@2x.png │ │ │ │ ├── icon-57.png │ │ │ │ ├── icon-57@2x.png │ │ │ │ ├── icon-60@2x.png │ │ │ │ ├── icon-60@3x.png │ │ │ │ ├── icon-72.png │ │ │ │ ├── icon-72@2x.png │ │ │ │ ├── icon-76.png │ │ │ │ ├── icon-76@2x.png │ │ │ │ └── icon-83.5@2x.png │ │ │ ├── Contents.json │ │ │ ├── LaunchImage.launchimage │ │ │ │ ├── Contents.json │ │ │ │ ├── Default-568h@2x.png │ │ │ │ ├── Default-667h@2x.png │ │ │ │ ├── Default-736h@3x.png │ │ │ │ ├── Default-Landscape.png │ │ │ │ ├── Default-Landscape@2x.png │ │ │ │ ├── Default-Landscape@3x.png │ │ │ │ ├── Default-Portrait.png │ │ │ │ ├── Default-Portrait@2x.png │ │ │ │ ├── Default.png │ │ │ │ └── Default@2x.png │ │ │ ├── LaunchScreen.AspectFill.imageset │ │ │ │ ├── Contents.json │ │ │ │ ├── LaunchScreen-AspectFill.png │ │ │ │ └── LaunchScreen-AspectFill@2x.png │ │ │ └── LaunchScreen.Center.imageset │ │ │ │ ├── Contents.json │ │ │ │ ├── LaunchScreen-Center.png │ │ │ │ └── LaunchScreen-Center@2x.png │ │ │ ├── Info.plist │ │ │ ├── LaunchScreen.storyboard │ │ │ └── build.xcconfig │ ├── app.css │ ├── app.ts │ ├── bundle-config.ts │ ├── main-page.ts │ ├── main-page.xml │ ├── package.json │ ├── vendor-platform.android.ts │ ├── vendor-platform.ios.ts │ └── vendor.ts ├── package-lock.json ├── package.json ├── references.d.ts ├── report │ ├── report.html │ └── stats.json ├── tsconfig.json └── webpack.config.js ├── gruntfile.js ├── nativescript-purchase.d.ts ├── package-lock.json ├── package.json ├── platforms └── android │ └── include.gradle ├── product ├── package.json ├── product-common.ts ├── product.android.ts ├── product.d.ts └── product.ios.ts ├── purchase-common.ts ├── purchase.android.ts ├── purchase.d.ts ├── purchase.ios.ts ├── references.d.ts ├── transaction ├── package.json ├── transaction-common.ts ├── transaction.android.ts ├── transaction.d.ts └── transaction.ios.ts ├── tsconfig.json ├── tslint.json └── typings └── InAppBillingHelper.android.d.ts /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear on external disk 35 | .Spotlight-V100 36 | .Trashes 37 | 38 | # Directories potentially created on remote AFP share 39 | .AppleDB 40 | .AppleDesktop 41 | Network Trash Folder 42 | Temporary Items 43 | .apdisk 44 | 45 | bin 46 | obj 47 | .vs 48 | .tscache 49 | *.user 50 | *.js 51 | *.map 52 | !gruntfile.js 53 | node_modules 54 | *.tmp.* 55 | demo/platforms 56 | demo/lib 57 | !karma.conf.js 58 | !webpack.*.js -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | 3 | android: 4 | components: 5 | - tools 6 | - platform-tools 7 | - build-tools-23.0.3 # needed for native src compile 8 | - build-tools-28.0.3 9 | - android-22 # needed for native src compile 10 | - android-23 11 | - android-28 12 | - extra-android-m2repository 13 | 14 | before_cache: 15 | - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock 16 | 17 | cache: 18 | directories: 19 | - .nvm 20 | - $HOME/.gradle/caches/ 21 | - $HOME/.gradle/wrapper/ 22 | 23 | install: 24 | - echo no | npm install -g nativescript 25 | - tns usage-reporting disable 26 | - tns error-reporting disable 27 | - echo no | npm install -g grunt-cli 28 | - npm install 29 | - grunt compile 30 | 31 | matrix: 32 | include: 33 | - stage: lint 34 | language: android 35 | jdk: oraclejdk8 36 | os: linux 37 | before_install: nvm install 8.11.3 38 | script: grunt lint 39 | 40 | # - stage: build 41 | # language: android 42 | # os: linux 43 | # env: 44 | # - Android="28" 45 | # jdk: oraclejdk8 46 | # before_install: nvm install 8.11.3 47 | # script: "grunt ci:build:android" 48 | # 49 | # - stage: build 50 | # os: osx 51 | # env: 52 | # - iOS="10.3" 53 | # - Xcode="9.4" 54 | # osx_image: xcode9.4 55 | # language: node_js 56 | # node_js: "8" 57 | # jdk: oraclejdk8 58 | # before_install: 59 | # - pip install --upgrade pip 60 | # - pip install --user --upgrade matplotlib 61 | # - pip install six 62 | # script: "grunt ci:build:ios" 63 | # 64 | # - stage: webpack 65 | # language: android 66 | # os: linux 67 | # env: 68 | # - Android="28" 69 | # - Platform="Android" 70 | # jdk: oraclejdk8 71 | # before_install: nvm install 8.11.3 72 | # script: "grunt ci:webpack:android" 73 | # 74 | # - stage: webpack 75 | # os: osx 76 | # env: 77 | # - iOS="10.3" 78 | # - Xcode="9.4" 79 | # - Platform="iOS" 80 | # osx_image: xcode9.4 81 | # language: node_js 82 | # node_js: "8" 83 | # jdk: oraclejdk8 84 | # before_install: 85 | # - pip install --upgrade pip 86 | # - pip install --user --upgrade matplotlib 87 | # - pip install six 88 | # script: "grunt ci:webpack:ios" 89 | 90 | - stage: deploy 91 | if: branch = release 92 | language: android 93 | jdk: oraclejdk8 94 | os: linux 95 | before_install: nvm install 8.11.3 96 | script: skip 97 | before_deploy: 98 | - cd bin/dist 99 | deploy: 100 | provider: npm 101 | email: "peter@tangrasoft.com" 102 | api_key: 103 | secure: "rE7dB+LJ0uIynkPi/yrDM4fkJTjCaNqVtpHgSzt9NG3s4o8Hk3ckk05q7fLA1pHs+8P5nmucrHVog+uBASssxBv9EgCiHfbN8QsacCG35rpBERp9/NIBa+Cc2stPWxKd4nwBasFxcFU2SeLgsQBXpsch1azYxXpgfP9ct+uYnXIq8b8kS46ZP9jRbsIV9h0QDylA5wQvbhkn5ixlKXlgBtQA421yW6mEuRTiULkvr/wC6BwJS4qVzvtVjYl1ldzRYwjlO0M5p+toR2QMdJuQJ7lbDWxX012RJrhjNaf/U2TGFZ8+Fizkji+xSe2UASUmBAsinzf4KNmhok0bAp/o5l2I7nGffzHRiVjMrPLpIvY9P6fYrFz+xdA59k/RVFX/LV+AzPH1ecpmAEPCidgfbXgMC7AsQHiyFi47nBGwSsU4vpMQ+yROmJTMesy61ZivOAzP4qXipvcTJWpnLtvKeYYpxjQwcg8+zRm0LVRSg9SoU0aJger5vep6jj+6JunHUNxxPgk/kiVWmYW9Zn6XpWxEqFfObGaLKZNKTqHLYEfltTFskLr6EPw0WqsXAuGoidBOW9oxPy6ldrxEpsPOKovWl9j/0A3AsvTcQXkqj6iyEIDDP5IL3k/ZO9BJ2ia+IAXlY71LKcxqaTYzAzfOd9zMPtnAfM7Zj/ArW1gvc5U=" 104 | skip_cleanup: true 105 | on: 106 | branch: release 107 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | // Place your settings in this file to overwrite default and user settings. 2 | { 3 | "files.exclude": { 4 | "**/.git": true, 5 | "**/.svn": true, 6 | "**/.hg": true, 7 | "**/.DS_Store": true, 8 | "demo/**": true, 9 | "bin/**": true 10 | } 11 | , 12 | "typescript.tsdk": "./node_modules/typescript/lib" 13 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the tasks.json format 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "type": "grunt", 8 | "task": "build", 9 | "problemMatcher": [ 10 | "$tsc", 11 | "$tslint4" 12 | ], 13 | "group": { 14 | "kind": "build", 15 | "isDefault": true 16 | } 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2016-2019 Tangra Inc. 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **This repo only supports NativeScript pre-6.0. The latest version of the plugin supporting NS 6+ is availble as part of [ProPlugins](https://proplugins.org).** 2 | # NativeScript In-App Purchases plugin 3 | [![Build Status](https://travis-ci.org/PeterStaev/nativescript-purchase.svg?branch=master)](https://travis-ci.org/PeterStaev/nativescript-purchase) 4 | [![npm downloads](https://img.shields.io/npm/dm/nativescript-purchase.svg)](https://www.npmjs.com/package/nativescript-purchase) 5 | [![npm downloads](https://img.shields.io/npm/dt/nativescript-purchase.svg)](https://www.npmjs.com/package/nativescript-purchase) 6 | [![npm](https://img.shields.io/npm/v/nativescript-purchase.svg)](https://www.npmjs.com/package/nativescript-purchase) 7 | 8 | A NativeScript plugin for making in-app purchases. 9 | 10 | ## Installation 11 | Run the following command from the root of your project: 12 | 13 | `tns plugin add nativescript-purchase` 14 | 15 | This command automatically installs the necessary files, as well as stores nativescript-purchase as a dependency in your project's package.json file. 16 | 17 | In order to get IntelliSense and make TypeScript compile without problems, add the following to your `references.d.ts`: 18 | ```typescript 19 | /// 20 | ``` 21 | 22 | ## Configuration 23 | In order for your in-app purchases to be recognized by the plugin, you must configure those on the Google/iTunes side. You can check the [in-depth tutorials](#in-depth-tutorial) at the bottom of the page to see how to do it step-by-step. 24 | 25 | ## API 26 | 27 | ### Static Properties 28 | * **transactionUpdatedEvent** - *String* 29 | String value used when hooking to `transactionUpdated` event. 30 | 31 | ### Static methods 32 | * **init(string[]): Promise** 33 | Initializes the plugin for work with the specified in-app purchase identifiers. 34 | 35 | * **getProducts(): Promise** 36 | Returns the product details *(see below)* for the in-app purchase identifiers that were used in init. 37 | 38 | * **canMakePayments(): boolean** 39 | Checks whether the current user is allowed to make in-app purchases. 40 | 41 | * **buyProduct(Product, string?): void** 42 | Buys the given product. On Android you can send custom string data that will be present in the `Transaction`. 43 | 44 | * **consumePurchase(string): Promise** 45 | Consumes the purchases represented by the given transaction token. If the promise returns `0` the consume was successful. Note that this is needed only for Android. For iOS each purchase is automatically consumed when it is set up as a consumabel product in iTunes. 46 | 47 | * **restorePurchases(): Promise** 48 | Restores previous purchased items for the current user. On Android, returns a promise for when the purchases have been restored. On iOS, returns a completed promise (as you can use getStoreReceipt to get the receipt instantly anytime). 49 | 50 | * **getStoreReceipt(): string** 51 | Gets the application's Base64 encoded store receipt for the currently logged in store user. This is useful when checking subscription status under iOS. For Android the function always returns `undefined`. 52 | 53 | * **refreshStoreReceipt(): Promise** 54 | Refreshes the store receipt for the currently logged in store user. This is useful when a transaction is invalid or missing. On iOS, returns a completed promise once the refresh is complete. 55 | 56 | ### Events 57 | * **transactionUpdated** 58 | Triggered a buy/restore transaction changes its state. You receive a `Transaction` object where you can check the status and other properties *(see below)* of the transaction. 59 | 60 | ### `Product` properties 61 | * **nativeValue** 62 | The native object representing the product. On iOS this will be an instance of `SKProduct`, and on Android this will be a `org.json.JSONObject` 63 | 64 | * **productIdentifier** - *string* 65 | The in-app product identifier as setup on iTunes Connect or Google Store. 66 | 67 | * **localizedTitle** - *string* 68 | The title of the product based on the user's phone localization. 69 | 70 | * **localizedDescription** - *string* 71 | The description of the product based on the user's phone localization. 72 | 73 | * **priceAmount** - *number* 74 | The numerical value of the price for this in-app product based on the currency of the user's app store. 75 | 76 | * **priceFormatted** - *string* 77 | The formatted `priceAmount` with the corresponding currency symbol of the user's app store. 78 | 79 | * **priceCurrencyCode** - *string* 80 | The [ISO4217](https://en.wikipedia.org/wiki/ISO_4217#Active_codes) currency code of the price (BGN, EUR, USD, etc.) 81 | 82 | * **productType** - *"inapp" | "subs"* 83 | The type of the product - in-app purchase or subscription. 84 | 85 | * **subscriptionPeriod** - *string* 86 | The [ISO8601](https://en.wikipedia.org/wiki/ISO_8601#Durations) duration of the subscription. For example `P1D` stands for a daily subscription, `P1M` is a monthly subscription, `P3M` is a three month subscription. The property has a value only for products of type `"subs"`. 87 | 88 | ### `Transaction` properties 89 | * **nativeValue** 90 | The native value representing the transaction. On iOS this will be an instance of `SKPaymentTransactio` and on Android this will be a `org.json.JSONObject`. 91 | 92 | * **transactionState** - *string* 93 | The state of the transaction. Can be one of the following: 94 | * Purchased 95 | * Restored 96 | * Failed 97 | * Deferred *(iOS only)* 98 | * Purchasing *(iOS only)* 99 | * Refunded *(Android only)* 100 | 101 | * **productIdentifier** - *string* 102 | The in-app product identifier that triggerred this transaction. 103 | 104 | * **transactionIdentifier** - *string* 105 | The unique identifier of the transaction. 106 | 107 | * **transactionDate** - *Date* 108 | The date of the transaction. 109 | 110 | * **transactionReceipt** - *string* 111 | The Base64 encoded transaction receipt. You can use this to do additional verification on your backend. 112 | 113 | * **originalTransaction** - *Transaction* 114 | This will be present only when restoring purchases and will contain the original transaction that purchased a given product. 115 | 116 | * **developerPayload** - *string* 117 | Custom data sent with `buyProduct`. 118 | 119 | * **dataSignature** - *string (Android only)* 120 | The signature for the transaction. 121 | 122 | ## Usage 123 | 124 | First we need to initialize the plugin with a list for product identifier that will be available for purchase. This is best to be done before the application starts. 125 | 126 | Note that it is possible that the initialization of the plugin takes more time than the application to boot. So especially in the cases that you load the products on your landing page, it is best that to save the `Promise` returned by the `init()` method and then check it before trying to get your products. 127 | 128 | ```typescript 129 | import * as purchase from "nativescript-purchase"; 130 | (global as any).purchaseInitPromise = purchase.init(["com.sample.purchase.coolproduct1", "com.sample.purchase.coolproduct2"]); 131 | ``` 132 | 133 | To get the actual products with details (like title, price, currency, etc.) you should use: 134 | ```typescript 135 | import { Product } from "nativescript-purchase/product"; 136 | 137 | (global as any).purchaseInitPromise.then(() => { 138 | purchase.getProducts().then((products: Array) => { 139 | products.forEach((product: Product) => { 140 | console.log(product.productIdentifier); 141 | console.log(product.localizedTitle); 142 | console.log(product.priceFormatted); 143 | }); 144 | }); 145 | }); 146 | ``` 147 | 148 | Before proceeding with buying items you should hook up to the `transactionUpdated` event. This way you will receive information about the transaction state while it is executing and take necessary action when the transaction completes: 149 | ```typescript 150 | import { Transaction, TransactionState } from "nativescript-purchase/transaction"; 151 | import * as applicationSettings from "application-settings"; 152 | 153 | purchase.on(purchase.transactionUpdatedEvent, (transaction: Transaction) => { 154 | if (transaction.transactionState === TransactionState.Purchased) { 155 | alert(`Congratulations you just bought ${transaction.productIdentifier}!`); 156 | console.log(transaction.transactionDate); 157 | console.log(transaction.transactionIdentifier); 158 | applicationSettings.setBoolean(transaction.productIdentifier, true); 159 | } 160 | else if (transaction.transactionState === TransactionState.Restored) { 161 | console.log(`Purchase of ${transaction.originalTransaction.productIdentifier} restored.`); 162 | console.log(transaction.originalTransaction); 163 | console.log(transaction.originalTransaction.transactionDate); 164 | applicationSettings.setBoolean(transaction.originalTransaction.productIdentifier, true); 165 | } 166 | else if (transaction.transactionState === TransactionState.Failed) { 167 | alert(`Purchase of ${transaction.productIdentifier} failed!`); 168 | } 169 | }); 170 | ``` 171 | 172 | Now let's buy a product! 173 | ```typescript 174 | if (purchase.canMakePayments()) { 175 | // NOTE: 'product' must be the same instance as the one returned from getProducts() 176 | purchase.buyProduct(product); 177 | } 178 | else { 179 | alert("Sorry, your account is not eligible to make payments!"); 180 | } 181 | ``` 182 | 183 | NOTE: Because of the difference between iOS and Android in terms of consuming purchases - for iOS this is defined 184 | in the product you add in iTunes Connect and it is consumed automatically, where for Android it has to be done manually - 185 | if you will be supporting Android you will have to manually consume the purchase by calling the `consumePurchase` method. 186 | The methods takes a single parameter that is the receipt from the transaction: 187 | ```typescript 188 | purchase.on(purchase.transactionUpdatedEvent, (transaction: Transaction) => { 189 | if (transaction.transactionState === TransactionState.Purchased && transaction.productIdentifier.indexOf(".consume") >= 0) { 190 | purchase.consumePurchase(transaction.transactionReceipt) 191 | .then((responseCode) => console.log(responseCode)) // If responseCode === 0 the purchase has been successfully consumed 192 | .catch((e) => console.log(e)); 193 | } 194 | }); 195 | ``` 196 | 197 | And to restore previous purchases to the user's device: 198 | ```typescript 199 | purchase.restorePurchases(); 200 | ``` 201 | 202 | ## Demo 203 | This repository includes a plain NativeScript demo. Note that in order to set up and run the demo you need to have the Grunt CLI installed globally. If you don't have it installed, you can do it by running the following in your shell: 204 | ```shell 205 | $ npm install -g grunt-cli 206 | ``` 207 | Once you have Grunt CLI set up in order to set it up the demo run the following in your shell: 208 | ```shell 209 | $ git clone https://github.com/peterstaev/nativescript-purchase 210 | $ cd nativescript-purchase 211 | $ npm install 212 | $ grunt compile 213 | $ cd demo 214 | ``` 215 | You will not be able to directly run the demo, becuase you need to add your purchases to the stores. Also since I already registered the application ID you will have to change that in the `package.json` file located in the `demo` folder. So make sure you read and follow the [in-depth tutorials](#in-depth-tutorial) below in order to get started with the demo. 216 | 217 | ## In-depth Tutorial 218 | 1. [Adding the plugin to your application and creating a purchase workflow](https://www.tangrainc.com/blog/2017/02/implementing-app-purchases-nativescript-application-part-1/) 219 | 2. [Configuring iTunes Connect and making purchases on iOS](https://www.tangrainc.com/blog/2017/03/implementing-app-purchases-nativescript-application-part-2/) 220 | 3. [Configuring Google Play Store and making purchases on Android](https://www.tangrainc.com/blog/2017/06/implementing-app-purchases-nativescript-application-part-3/) 221 | 222 | ## Donate 223 | [![Donate](https://img.shields.io/badge/paypal-donate-brightgreen.svg)](https://bit.ly/2AS9QKB) 224 | 225 | `bitcoin:14fjysmpwLvSsAskvLASw6ek5XfhTzskHC` 226 | 227 | ![Donate](https://www.tangrainc.com/qr.png) 228 | -------------------------------------------------------------------------------- /android/inappbilling/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /android/inappbilling/.idea/.name: -------------------------------------------------------------------------------- 1 | inappbilling -------------------------------------------------------------------------------- /android/inappbilling/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /android/inappbilling/.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /android/inappbilling/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /android/inappbilling/.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /android/inappbilling/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | -------------------------------------------------------------------------------- /android/inappbilling/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /android/inappbilling/.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /android/inappbilling/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.1.0' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | -------------------------------------------------------------------------------- /android/inappbilling/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /android/inappbilling/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/android/inappbilling/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /android/inappbilling/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip 7 | -------------------------------------------------------------------------------- /android/inappbilling/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /android/inappbilling/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /android/inappbilling/inappbillinghelper/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /android/inappbilling/inappbillinghelper/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 22 5 | buildToolsVersion "23.0.3" 6 | 7 | defaultConfig { 8 | minSdkVersion 17 9 | targetSdkVersion 22 10 | versionCode 1 11 | versionName "1.0" 12 | } 13 | compileOptions { 14 | targetCompatibility JavaVersion.VERSION_1_7 15 | sourceCompatibility JavaVersion.VERSION_1_7 16 | } 17 | } 18 | 19 | dependencies { 20 | compile fileTree(include: ['*.jar'], dir: 'libs') 21 | compile "com.google.guava:guava:18.0" 22 | } 23 | -------------------------------------------------------------------------------- /android/inappbilling/inappbillinghelper/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /usr/local/Cellar/android-sdk/24.4.1_1/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /android/inappbilling/inappbillinghelper/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /android/inappbilling/inappbillinghelper/src/main/aidl/com/android/vending/billing/IInAppBillingService.aidl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.android.vending.billing; 18 | 19 | import android.os.Bundle; 20 | 21 | /** 22 | * InAppBillingService is the service that provides in-app billing version 3 and beyond. 23 | * This service provides the following features: 24 | * 1. Provides a new API to get details of in-app items published for the app including 25 | * price, type, title and description. 26 | * 2. The purchase flow is synchronous and purchase information is available immediately 27 | * after it completes. 28 | * 3. Purchase information of in-app purchases is maintained within the Google Play system 29 | * till the purchase is consumed. 30 | * 4. An API to consume a purchase of an inapp item. All purchases of one-time 31 | * in-app items are consumable and thereafter can be purchased again. 32 | * 5. An API to get current purchases of the user immediately. This will not contain any 33 | * consumed purchases. 34 | * 35 | * All calls will give a response code with the following possible values 36 | * RESULT_OK = 0 - success 37 | * RESULT_USER_CANCELED = 1 - user pressed back or canceled a dialog 38 | * RESULT_BILLING_UNAVAILABLE = 3 - this billing API version is not supported for the type requested 39 | * RESULT_ITEM_UNAVAILABLE = 4 - requested SKU is not available for purchase 40 | * RESULT_DEVELOPER_ERROR = 5 - invalid arguments provided to the API 41 | * RESULT_ERROR = 6 - Fatal error during the API action 42 | * RESULT_ITEM_ALREADY_OWNED = 7 - Failure to purchase since item is already owned 43 | * RESULT_ITEM_NOT_OWNED = 8 - Failure to consume since item is not owned 44 | */ 45 | interface IInAppBillingService { 46 | /** 47 | * Checks support for the requested billing API version, package and in-app type. 48 | * Minimum API version supported by this interface is 3. 49 | * @param apiVersion the billing version which the app is using 50 | * @param packageName the package name of the calling app 51 | * @param type type of the in-app item being purchased "inapp" for one-time purchases 52 | * and "subs" for subscription. 53 | * @return RESULT_OK(0) on success, corresponding result code on failures 54 | */ 55 | int isBillingSupported(int apiVersion, String packageName, String type); 56 | 57 | /** 58 | * Provides details of a list of SKUs 59 | * Given a list of SKUs of a valid type in the skusBundle, this returns a bundle 60 | * with a list JSON strings containing the productId, price, title and description. 61 | * This API can be called with a maximum of 20 SKUs. 62 | * @param apiVersion billing API version that the Third-party is using 63 | * @param packageName the package name of the calling app 64 | * @param skusBundle bundle containing a StringArrayList of SKUs with key "ITEM_ID_LIST" 65 | * @return Bundle containing the following key-value pairs 66 | * "RESPONSE_CODE" with int value, RESULT_OK(0) if success, other response codes on 67 | * failure as listed above. 68 | * "DETAILS_LIST" with a StringArrayList containing purchase information 69 | * in JSON format similar to: 70 | * '{ "productId" : "exampleSku", "type" : "inapp", "price" : "$5.00", 71 | * "title : "Example Title", "description" : "This is an example description" }' 72 | */ 73 | Bundle getSkuDetails(int apiVersion, String packageName, String type, in Bundle skusBundle); 74 | 75 | /** 76 | * Returns a pending intent to launch the purchase flow for an in-app item by providing a SKU, 77 | * the type, a unique purchase token and an optional developer payload. 78 | * @param apiVersion billing API version that the app is using 79 | * @param packageName package name of the calling app 80 | * @param sku the SKU of the in-app item as published in the developer console 81 | * @param type the type of the in-app item ("inapp" for one-time purchases 82 | * and "subs" for subscription). 83 | * @param developerPayload optional argument to be sent back with the purchase information 84 | * @return Bundle containing the following key-value pairs 85 | * "RESPONSE_CODE" with int value, RESULT_OK(0) if success, other response codes on 86 | * failure as listed above. 87 | * "BUY_INTENT" - PendingIntent to start the purchase flow 88 | * 89 | * The Pending intent should be launched with startIntentSenderForResult. When purchase flow 90 | * has completed, the onActivityResult() will give a resultCode of OK or CANCELED. 91 | * If the purchase is successful, the result data will contain the following key-value pairs 92 | * "RESPONSE_CODE" with int value, RESULT_OK(0) if success, other response codes on 93 | * failure as listed above. 94 | * "INAPP_PURCHASE_DATA" - String in JSON format similar to 95 | * '{"orderId":"12999763169054705758.1371079406387615", 96 | * "packageName":"com.example.app", 97 | * "productId":"exampleSku", 98 | * "purchaseTime":1345678900000, 99 | * "purchaseToken" : "122333444455555", 100 | * "developerPayload":"example developer payload" }' 101 | * "INAPP_DATA_SIGNATURE" - String containing the signature of the purchase data that 102 | * was signed with the private key of the developer 103 | * TODO: change this to app-specific keys. 104 | */ 105 | Bundle getBuyIntent(int apiVersion, String packageName, String sku, String type, 106 | String developerPayload); 107 | 108 | /** 109 | * Returns the current SKUs owned by the user of the type and package name specified along with 110 | * purchase information and a signature of the data to be validated. 111 | * This will return all SKUs that have been purchased in V3 and managed items purchased using 112 | * V1 and V2 that have not been consumed. 113 | * @param apiVersion billing API version that the app is using 114 | * @param packageName package name of the calling app 115 | * @param type the type of the in-app items being requested 116 | * ("inapp" for one-time purchases and "subs" for subscription). 117 | * @param continuationToken to be set as null for the first call, if the number of owned 118 | * skus are too many, a continuationToken is returned in the response bundle. 119 | * This method can be called again with the continuation token to get the next set of 120 | * owned skus. 121 | * @return Bundle containing the following key-value pairs 122 | * "RESPONSE_CODE" with int value, RESULT_OK(0) if success, other response codes on 123 | * failure as listed above. 124 | * "INAPP_PURCHASE_ITEM_LIST" - StringArrayList containing the list of SKUs 125 | * "INAPP_PURCHASE_DATA_LIST" - StringArrayList containing the purchase information 126 | * "INAPP_DATA_SIGNATURE_LIST"- StringArrayList containing the signatures 127 | * of the purchase information 128 | * "INAPP_CONTINUATION_TOKEN" - String containing a continuation token for the 129 | * next set of in-app purchases. Only set if the 130 | * user has more owned skus than the current list. 131 | */ 132 | Bundle getPurchases(int apiVersion, String packageName, String type, String continuationToken); 133 | 134 | /** 135 | * Consume the last purchase of the given SKU. This will result in this item being removed 136 | * from all subsequent responses to getPurchases() and allow re-purchase of this item. 137 | * @param apiVersion billing API version that the app is using 138 | * @param packageName package name of the calling app 139 | * @param purchaseToken token in the purchase information JSON that identifies the purchase 140 | * to be consumed 141 | * @return 0 if consumption succeeded. Appropriate error values for failures. 142 | */ 143 | int consumePurchase(int apiVersion, String packageName, String purchaseToken); 144 | } 145 | -------------------------------------------------------------------------------- /android/inappbilling/inappbillinghelper/src/main/java/com/tangrainc/inappbilling/InAppBillingHelper.java: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) 2019 Tangra Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ***************************************************************************** */ 16 | 17 | package com.tangrainc.inappbilling; 18 | 19 | import android.app.Activity; 20 | import android.app.PendingIntent; 21 | import android.os.IBinder; 22 | import android.os.Bundle; 23 | 24 | import android.content.ComponentName; 25 | import android.content.ServiceConnection; 26 | import android.content.Intent; 27 | import android.content.Context; 28 | import android.os.RemoteException; 29 | import android.util.Log; 30 | 31 | import com.android.vending.billing.IInAppBillingService; 32 | import com.google.common.util.concurrent.*; 33 | 34 | import org.json.*; 35 | 36 | import java.util.ArrayList; 37 | import java.util.Arrays; 38 | import java.util.concurrent.Callable; 39 | import java.util.concurrent.Executors; 40 | 41 | public class InAppBillingHelper { 42 | 43 | private static final String TAG = "InAppBillingHelper"; 44 | public static final int BUY_INTENT_REQUEST_CODE = 4590; 45 | 46 | private IInAppBillingService _service; 47 | private ListeningExecutorService _executor; 48 | private String[] _productIdentifiers; 49 | private Context _context; 50 | 51 | public InAppBillingHelper(Context context, String[] productIdentifiers) { 52 | _executor = MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor()); 53 | _productIdentifiers = productIdentifiers; 54 | _context = context; 55 | ServiceConnection _serviceConn = new ServiceConnection() { 56 | @Override 57 | public void onServiceDisconnected(ComponentName name) { 58 | Log.d(TAG, "Billing Service disconnected."); 59 | _service = null; 60 | } 61 | 62 | @Override 63 | public void onServiceConnected(ComponentName name, IBinder service) { 64 | Log.d(TAG, "Billing Service connected."); 65 | _service = IInAppBillingService.Stub.asInterface(service); 66 | } 67 | }; 68 | 69 | Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND"); 70 | serviceIntent.setPackage("com.android.vending"); 71 | _context.bindService(serviceIntent, _serviceConn, Context.BIND_AUTO_CREATE); 72 | } 73 | 74 | public ListenableFuture getProducts(final String type) { 75 | return _executor.submit(new Callable() { 76 | @Override 77 | public JSONObject[] call() throws Exception { 78 | // Wait for the service to be initialized (if call too soon after constructor) 79 | int loop = 0; 80 | while (_service == null && loop < 20) { 81 | Thread.sleep(500); 82 | loop++; 83 | } 84 | if (_service == null) { 85 | throw new Exception("Billing service could not be connected for 10 secs! May be running on an emulator w/o Google Service?"); 86 | } 87 | 88 | ArrayList productIdentifiers = new ArrayList<>(Arrays.asList(_productIdentifiers)); 89 | ArrayList result = new ArrayList<>(); 90 | // Process 20 items at a time 91 | while (productIdentifiers.size() > 0) { 92 | ArrayList productIdSubList = new ArrayList<>(productIdentifiers.subList(0, Math.min(20, productIdentifiers.size()))); 93 | productIdentifiers.removeAll(productIdSubList); 94 | 95 | Bundle queryProducts = new Bundle(); 96 | queryProducts.putStringArrayList("ITEM_ID_LIST", productIdSubList); 97 | 98 | Bundle productDetails = _service.getSkuDetails(3, _context.getPackageName(), type, queryProducts); 99 | 100 | int response = productDetails.getInt("RESPONSE_CODE"); 101 | if (response == 0) { 102 | ArrayList responseList = productDetails.getStringArrayList("DETAILS_LIST"); 103 | 104 | for (String thisResponse : responseList) { 105 | result.add(new JSONObject(thisResponse)); 106 | } 107 | 108 | } else { 109 | throw new Exception("Response from service: " + response); 110 | } 111 | } 112 | return result.toArray(new JSONObject[0]); 113 | } 114 | }); 115 | } 116 | 117 | public void startBuyIntent(Activity foregroundActivity, String productIdentifier, String type, String payload) throws Exception { 118 | Bundle buyIntentBundle = _service.getBuyIntent(3, _context.getPackageName(), productIdentifier, type, payload); 119 | PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT"); 120 | 121 | if (pendingIntent == null) { 122 | throw new Exception("Product already purchased!"); 123 | } 124 | 125 | foregroundActivity.startIntentSenderForResult(pendingIntent.getIntentSender(), BUY_INTENT_REQUEST_CODE, new Intent(), 0, 0, 0); 126 | } 127 | 128 | public ListenableFuture consumePurchase(final String token) { 129 | return _executor.submit(new Callable() { 130 | @Override 131 | public Integer call() throws Exception { 132 | // Wait for the service to be initialized (if call too soon after constructor) 133 | int loop = 0; 134 | while (_service == null && loop < 20) { 135 | Thread.sleep(500); 136 | loop++; 137 | } 138 | if (_service == null) { 139 | throw new Exception("Billing service could not be connected for 10 secs! May be running on an emulator w/o Google Service?"); 140 | } 141 | 142 | return _service.consumePurchase(3, _context.getPackageName(), token); 143 | } 144 | }); 145 | } 146 | 147 | public ListenableFuture getPurchases(String type) { 148 | return this.getPurchases(null, type); 149 | } 150 | 151 | public ListenableFuture getPurchases(final String continuationToken, final String type) { 152 | return _executor.submit(new Callable() { 153 | @Override 154 | public JSONObject[] call() throws Exception { 155 | Log.d(TAG, "Getting Purchases..."); 156 | 157 | ArrayList result = new ArrayList< >(); 158 | Bundle ownedItems = _service.getPurchases(3, _context.getPackageName(), type, continuationToken); 159 | int response = ownedItems.getInt("RESPONSE_CODE"); 160 | 161 | if (response == 0) { 162 | ArrayList purchaseDataList = ownedItems.getStringArrayList("INAPP_PURCHASE_DATA_LIST"); 163 | ArrayList signatureList = ownedItems.getStringArrayList("INAPP_DATA_SIGNATURE_LIST"); 164 | String newContinuationToken = ownedItems.getString("INAPP_CONTINUATION_TOKEN"); 165 | 166 | for (int i = 0; i < purchaseDataList.size(); i++) { 167 | String purchaseData = purchaseDataList.get(i); 168 | String signature = signatureList.get(i); 169 | JSONObject resultItem = new JSONObject(purchaseData); 170 | 171 | resultItem.put("signature", signature); 172 | result.add(resultItem); 173 | } 174 | 175 | if (newContinuationToken != null) { 176 | result.addAll(Arrays.asList(getPurchases(newContinuationToken).get())); 177 | } 178 | } 179 | else { 180 | throw new Exception("Response from service: " + response); 181 | } 182 | 183 | return result.toArray(new JSONObject[0]); 184 | } 185 | }); 186 | } 187 | } -------------------------------------------------------------------------------- /android/inappbilling/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':inappbillinghelper' 2 | -------------------------------------------------------------------------------- /demo/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "Launch on iOS Device", 6 | "type": "nativescript", 7 | "platform": "ios", 8 | "request": "launch", 9 | "appRoot": "${workspaceRoot}", 10 | "sourceMaps": true, 11 | "diagnosticLogging": false, 12 | "emulator": false 13 | }, 14 | { 15 | "name": "Attach on iOS Device", 16 | "type": "nativescript", 17 | "platform": "ios", 18 | "request": "attach", 19 | "appRoot": "${workspaceRoot}", 20 | "sourceMaps": true, 21 | "diagnosticLogging": false, 22 | "emulator": false 23 | }, 24 | { 25 | "name": "Launch on iOS Emulator", 26 | "type": "nativescript", 27 | "platform": "ios", 28 | "request": "launch", 29 | "appRoot": "${workspaceRoot}", 30 | "sourceMaps": true, 31 | "diagnosticLogging": false, 32 | "emulator": true 33 | }, 34 | { 35 | "name": "Attach on iOS Emulator", 36 | "type": "nativescript", 37 | "platform": "ios", 38 | "request": "attach", 39 | "appRoot": "${workspaceRoot}", 40 | "sourceMaps": true, 41 | "diagnosticLogging": false, 42 | "emulator": true 43 | }, 44 | { 45 | "name": "Launch on Android Device", 46 | "type": "nativescript", 47 | "platform": "android", 48 | "request": "launch", 49 | "appRoot": "${workspaceRoot}", 50 | "sourceMaps": true, 51 | "diagnosticLogging": false, 52 | "emulator": false 53 | }, 54 | { 55 | "name": "Launch on Android Emulator", 56 | "type": "nativescript", 57 | "platform": "android", 58 | "request": "launch", 59 | "appRoot": "${workspaceRoot}", 60 | "sourceMaps": true, 61 | "diagnosticLogging": false, 62 | "emulator": true 63 | }, 64 | { 65 | "name": "Attach on Android Device", 66 | "type": "nativescript", 67 | "platform": "android", 68 | "request": "attach", 69 | "appRoot": "${workspaceRoot}", 70 | "sourceMaps": false, 71 | "diagnosticLogging": false, 72 | "emulator": false 73 | }, 74 | { 75 | "name": "Attach on Android Emulator", 76 | "type": "nativescript", 77 | "platform": "android", 78 | "request": "attach", 79 | "appRoot": "${workspaceRoot}", 80 | "sourceMaps": false, 81 | "diagnosticLogging": false, 82 | "emulator": true 83 | } 84 | ] 85 | } -------------------------------------------------------------------------------- /demo/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | // Place your settings in this file to overwrite default and user settings. 2 | { 3 | "files.exclude": { 4 | "**/.git": true, 5 | "**/.DS_Store": true, 6 | "platforms": true, 7 | "app/**/*.js": true, 8 | "app/**/*.map": true 9 | } 10 | , 11 | "typescript.tsdk": "./node_modules/typescript/lib" 12 | } -------------------------------------------------------------------------------- /demo/app/App_Resources/Android/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | 13 | 16 | 17 | 18 | 19 | 20 | 21 | 27 | 28 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /demo/app/App_Resources/Android/app.gradle: -------------------------------------------------------------------------------- 1 | // Add your native dependencies here: 2 | 3 | // Uncomment to add recyclerview-v7 dependency 4 | //dependencies { 5 | // compile 'com.android.support:recyclerview-v7:+' 6 | //} 7 | 8 | android { 9 | defaultConfig { 10 | generatedDensities = [] 11 | applicationId = "com.tangrainc.purchasesample" 12 | } 13 | aaptOptions { 14 | additionalParameters "--no-version-vectors" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /demo/app/App_Resources/Android/drawable-hdpi/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/Android/drawable-hdpi/background.png -------------------------------------------------------------------------------- /demo/app/App_Resources/Android/drawable-hdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/Android/drawable-hdpi/icon.png -------------------------------------------------------------------------------- /demo/app/App_Resources/Android/drawable-hdpi/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/Android/drawable-hdpi/logo.png -------------------------------------------------------------------------------- /demo/app/App_Resources/Android/drawable-ldpi/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/Android/drawable-ldpi/background.png -------------------------------------------------------------------------------- /demo/app/App_Resources/Android/drawable-ldpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/Android/drawable-ldpi/icon.png -------------------------------------------------------------------------------- /demo/app/App_Resources/Android/drawable-ldpi/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/Android/drawable-ldpi/logo.png -------------------------------------------------------------------------------- /demo/app/App_Resources/Android/drawable-mdpi/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/Android/drawable-mdpi/background.png -------------------------------------------------------------------------------- /demo/app/App_Resources/Android/drawable-mdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/Android/drawable-mdpi/icon.png -------------------------------------------------------------------------------- /demo/app/App_Resources/Android/drawable-mdpi/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/Android/drawable-mdpi/logo.png -------------------------------------------------------------------------------- /demo/app/App_Resources/Android/drawable-nodpi/splash_screen.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /demo/app/App_Resources/Android/drawable-xhdpi/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/Android/drawable-xhdpi/background.png -------------------------------------------------------------------------------- /demo/app/App_Resources/Android/drawable-xhdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/Android/drawable-xhdpi/icon.png -------------------------------------------------------------------------------- /demo/app/App_Resources/Android/drawable-xhdpi/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/Android/drawable-xhdpi/logo.png -------------------------------------------------------------------------------- /demo/app/App_Resources/Android/drawable-xxhdpi/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/Android/drawable-xxhdpi/background.png -------------------------------------------------------------------------------- /demo/app/App_Resources/Android/drawable-xxhdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/Android/drawable-xxhdpi/icon.png -------------------------------------------------------------------------------- /demo/app/App_Resources/Android/drawable-xxhdpi/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/Android/drawable-xxhdpi/logo.png -------------------------------------------------------------------------------- /demo/app/App_Resources/Android/drawable-xxxhdpi/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/Android/drawable-xxxhdpi/background.png -------------------------------------------------------------------------------- /demo/app/App_Resources/Android/drawable-xxxhdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/Android/drawable-xxxhdpi/icon.png -------------------------------------------------------------------------------- /demo/app/App_Resources/Android/drawable-xxxhdpi/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/Android/drawable-xxxhdpi/logo.png -------------------------------------------------------------------------------- /demo/app/App_Resources/Android/values-v21/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3d5afe 4 | -------------------------------------------------------------------------------- /demo/app/App_Resources/Android/values-v21/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 11 | 14 | 15 | 16 | 19 | 20 | 23 | -------------------------------------------------------------------------------- /demo/app/App_Resources/Android/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #F5F5F5 4 | #757575 5 | #33B5E5 6 | #272734 7 | -------------------------------------------------------------------------------- /demo/app/App_Resources/Android/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 18 | 19 | 21 | 22 | 23 | 31 | 32 | 34 | 35 | 36 | 42 | 43 | 45 | 46 | -------------------------------------------------------------------------------- /demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "29x29", 5 | "idiom" : "iphone", 6 | "filename" : "icon-29.png", 7 | "scale" : "1x" 8 | }, 9 | { 10 | "size" : "29x29", 11 | "idiom" : "iphone", 12 | "filename" : "icon-29@2x.png", 13 | "scale" : "2x" 14 | }, 15 | { 16 | "size" : "29x29", 17 | "idiom" : "iphone", 18 | "filename" : "icon-29@3x.png", 19 | "scale" : "3x" 20 | }, 21 | { 22 | "size" : "40x40", 23 | "idiom" : "iphone", 24 | "filename" : "icon-40@2x.png", 25 | "scale" : "2x" 26 | }, 27 | { 28 | "size" : "40x40", 29 | "idiom" : "iphone", 30 | "filename" : "icon-40@3x.png", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "size" : "57x57", 35 | "idiom" : "iphone", 36 | "filename" : "icon-57.png", 37 | "scale" : "1x" 38 | }, 39 | { 40 | "size" : "57x57", 41 | "idiom" : "iphone", 42 | "filename" : "icon-57@2x.png", 43 | "scale" : "2x" 44 | }, 45 | { 46 | "size" : "60x60", 47 | "idiom" : "iphone", 48 | "filename" : "icon-60@2x.png", 49 | "scale" : "2x" 50 | }, 51 | { 52 | "size" : "60x60", 53 | "idiom" : "iphone", 54 | "filename" : "icon-60@3x.png", 55 | "scale" : "3x" 56 | }, 57 | { 58 | "size" : "29x29", 59 | "idiom" : "ipad", 60 | "filename" : "icon-29.png", 61 | "scale" : "1x" 62 | }, 63 | { 64 | "size" : "29x29", 65 | "idiom" : "ipad", 66 | "filename" : "icon-29@2x.png", 67 | "scale" : "2x" 68 | }, 69 | { 70 | "size" : "40x40", 71 | "idiom" : "ipad", 72 | "filename" : "icon-40.png", 73 | "scale" : "1x" 74 | }, 75 | { 76 | "size" : "40x40", 77 | "idiom" : "ipad", 78 | "filename" : "icon-40@2x.png", 79 | "scale" : "2x" 80 | }, 81 | { 82 | "size" : "50x50", 83 | "idiom" : "ipad", 84 | "filename" : "icon-50.png", 85 | "scale" : "1x" 86 | }, 87 | { 88 | "size" : "50x50", 89 | "idiom" : "ipad", 90 | "filename" : "icon-50@2x.png", 91 | "scale" : "2x" 92 | }, 93 | { 94 | "size" : "72x72", 95 | "idiom" : "ipad", 96 | "filename" : "icon-72.png", 97 | "scale" : "1x" 98 | }, 99 | { 100 | "size" : "72x72", 101 | "idiom" : "ipad", 102 | "filename" : "icon-72@2x.png", 103 | "scale" : "2x" 104 | }, 105 | { 106 | "size" : "76x76", 107 | "idiom" : "ipad", 108 | "filename" : "icon-76.png", 109 | "scale" : "1x" 110 | }, 111 | { 112 | "size" : "76x76", 113 | "idiom" : "ipad", 114 | "filename" : "icon-76@2x.png", 115 | "scale" : "2x" 116 | }, 117 | { 118 | "size" : "83.5x83.5", 119 | "idiom" : "ipad", 120 | "filename" : "icon-83.5@2x.png", 121 | "scale" : "2x" 122 | } 123 | ], 124 | "info" : { 125 | "version" : 1, 126 | "author" : "xcode" 127 | } 128 | } -------------------------------------------------------------------------------- /demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-29.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-29.png -------------------------------------------------------------------------------- /demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-29@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-29@2x.png -------------------------------------------------------------------------------- /demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-29@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-29@3x.png -------------------------------------------------------------------------------- /demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-40.png -------------------------------------------------------------------------------- /demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-40@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-40@2x.png -------------------------------------------------------------------------------- /demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-40@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-40@3x.png -------------------------------------------------------------------------------- /demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-50.png -------------------------------------------------------------------------------- /demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-50@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-50@2x.png -------------------------------------------------------------------------------- /demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-57.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-57.png -------------------------------------------------------------------------------- /demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-57@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-57@2x.png -------------------------------------------------------------------------------- /demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-60@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-60@2x.png -------------------------------------------------------------------------------- /demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-60@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-60@3x.png -------------------------------------------------------------------------------- /demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-72.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-72.png -------------------------------------------------------------------------------- /demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-72@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-72@2x.png -------------------------------------------------------------------------------- /demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-76.png -------------------------------------------------------------------------------- /demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-76@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-76@2x.png -------------------------------------------------------------------------------- /demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-83.5@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-83.5@2x.png -------------------------------------------------------------------------------- /demo/app/App_Resources/iOS/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "extent" : "full-screen", 5 | "idiom" : "iphone", 6 | "subtype" : "736h", 7 | "filename" : "Default-736h@3x.png", 8 | "minimum-system-version" : "8.0", 9 | "orientation" : "portrait", 10 | "scale" : "3x" 11 | }, 12 | { 13 | "extent" : "full-screen", 14 | "idiom" : "iphone", 15 | "subtype" : "736h", 16 | "filename" : "Default-Landscape@3x.png", 17 | "minimum-system-version" : "8.0", 18 | "orientation" : "landscape", 19 | "scale" : "3x" 20 | }, 21 | { 22 | "extent" : "full-screen", 23 | "idiom" : "iphone", 24 | "subtype" : "667h", 25 | "filename" : "Default-667h@2x.png", 26 | "minimum-system-version" : "8.0", 27 | "orientation" : "portrait", 28 | "scale" : "2x" 29 | }, 30 | { 31 | "orientation" : "portrait", 32 | "idiom" : "iphone", 33 | "filename" : "Default@2x.png", 34 | "extent" : "full-screen", 35 | "minimum-system-version" : "7.0", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "extent" : "full-screen", 40 | "idiom" : "iphone", 41 | "subtype" : "retina4", 42 | "filename" : "Default-568h@2x.png", 43 | "minimum-system-version" : "7.0", 44 | "orientation" : "portrait", 45 | "scale" : "2x" 46 | }, 47 | { 48 | "orientation" : "portrait", 49 | "idiom" : "ipad", 50 | "filename" : "Default-Portrait.png", 51 | "extent" : "full-screen", 52 | "minimum-system-version" : "7.0", 53 | "scale" : "1x" 54 | }, 55 | { 56 | "orientation" : "landscape", 57 | "idiom" : "ipad", 58 | "filename" : "Default-Landscape.png", 59 | "extent" : "full-screen", 60 | "minimum-system-version" : "7.0", 61 | "scale" : "1x" 62 | }, 63 | { 64 | "orientation" : "portrait", 65 | "idiom" : "ipad", 66 | "filename" : "Default-Portrait@2x.png", 67 | "extent" : "full-screen", 68 | "minimum-system-version" : "7.0", 69 | "scale" : "2x" 70 | }, 71 | { 72 | "orientation" : "landscape", 73 | "idiom" : "ipad", 74 | "filename" : "Default-Landscape@2x.png", 75 | "extent" : "full-screen", 76 | "minimum-system-version" : "7.0", 77 | "scale" : "2x" 78 | }, 79 | { 80 | "orientation" : "portrait", 81 | "idiom" : "iphone", 82 | "filename" : "Default.png", 83 | "extent" : "full-screen", 84 | "scale" : "1x" 85 | }, 86 | { 87 | "orientation" : "portrait", 88 | "idiom" : "iphone", 89 | "filename" : "Default@2x.png", 90 | "extent" : "full-screen", 91 | "scale" : "2x" 92 | }, 93 | { 94 | "orientation" : "portrait", 95 | "idiom" : "iphone", 96 | "filename" : "Default-568h@2x.png", 97 | "extent" : "full-screen", 98 | "subtype" : "retina4", 99 | "scale" : "2x" 100 | }, 101 | { 102 | "orientation" : "portrait", 103 | "idiom" : "ipad", 104 | "extent" : "to-status-bar", 105 | "scale" : "1x" 106 | }, 107 | { 108 | "orientation" : "portrait", 109 | "idiom" : "ipad", 110 | "filename" : "Default-Portrait.png", 111 | "extent" : "full-screen", 112 | "scale" : "1x" 113 | }, 114 | { 115 | "orientation" : "landscape", 116 | "idiom" : "ipad", 117 | "extent" : "to-status-bar", 118 | "scale" : "1x" 119 | }, 120 | { 121 | "orientation" : "landscape", 122 | "idiom" : "ipad", 123 | "filename" : "Default-Landscape.png", 124 | "extent" : "full-screen", 125 | "scale" : "1x" 126 | }, 127 | { 128 | "orientation" : "portrait", 129 | "idiom" : "ipad", 130 | "extent" : "to-status-bar", 131 | "scale" : "2x" 132 | }, 133 | { 134 | "orientation" : "portrait", 135 | "idiom" : "ipad", 136 | "filename" : "Default-Portrait@2x.png", 137 | "extent" : "full-screen", 138 | "scale" : "2x" 139 | }, 140 | { 141 | "orientation" : "landscape", 142 | "idiom" : "ipad", 143 | "extent" : "to-status-bar", 144 | "scale" : "2x" 145 | }, 146 | { 147 | "orientation" : "landscape", 148 | "idiom" : "ipad", 149 | "filename" : "Default-Landscape@2x.png", 150 | "extent" : "full-screen", 151 | "scale" : "2x" 152 | } 153 | ], 154 | "info" : { 155 | "version" : 1, 156 | "author" : "xcode" 157 | } 158 | } -------------------------------------------------------------------------------- /demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-568h@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-568h@2x.png -------------------------------------------------------------------------------- /demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-667h@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-667h@2x.png -------------------------------------------------------------------------------- /demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-736h@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-736h@3x.png -------------------------------------------------------------------------------- /demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-Landscape.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-Landscape.png -------------------------------------------------------------------------------- /demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-Landscape@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-Landscape@2x.png -------------------------------------------------------------------------------- /demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-Landscape@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-Landscape@3x.png -------------------------------------------------------------------------------- /demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-Portrait.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-Portrait.png -------------------------------------------------------------------------------- /demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-Portrait@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-Portrait@2x.png -------------------------------------------------------------------------------- /demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default.png -------------------------------------------------------------------------------- /demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default@2x.png -------------------------------------------------------------------------------- /demo/app/App_Resources/iOS/Assets.xcassets/LaunchScreen.AspectFill.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "LaunchScreen-AspectFill.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "LaunchScreen-AspectFill@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "scale" : "3x" 16 | } 17 | ], 18 | "info" : { 19 | "version" : 1, 20 | "author" : "xcode" 21 | } 22 | } -------------------------------------------------------------------------------- /demo/app/App_Resources/iOS/Assets.xcassets/LaunchScreen.AspectFill.imageset/LaunchScreen-AspectFill.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/iOS/Assets.xcassets/LaunchScreen.AspectFill.imageset/LaunchScreen-AspectFill.png -------------------------------------------------------------------------------- /demo/app/App_Resources/iOS/Assets.xcassets/LaunchScreen.AspectFill.imageset/LaunchScreen-AspectFill@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/iOS/Assets.xcassets/LaunchScreen.AspectFill.imageset/LaunchScreen-AspectFill@2x.png -------------------------------------------------------------------------------- /demo/app/App_Resources/iOS/Assets.xcassets/LaunchScreen.Center.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "LaunchScreen-Center.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "LaunchScreen-Center@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "scale" : "3x" 16 | } 17 | ], 18 | "info" : { 19 | "version" : 1, 20 | "author" : "xcode" 21 | } 22 | } -------------------------------------------------------------------------------- /demo/app/App_Resources/iOS/Assets.xcassets/LaunchScreen.Center.imageset/LaunchScreen-Center.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/iOS/Assets.xcassets/LaunchScreen.Center.imageset/LaunchScreen-Center.png -------------------------------------------------------------------------------- /demo/app/App_Resources/iOS/Assets.xcassets/LaunchScreen.Center.imageset/LaunchScreen-Center@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterStaev/nativescript-purchase/21295fdc37b8bad9a42dbc67099432532ab28294/demo/app/App_Resources/iOS/Assets.xcassets/LaunchScreen.Center.imageset/LaunchScreen-Center@2x.png -------------------------------------------------------------------------------- /demo/app/App_Resources/iOS/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | Purchase Sample 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | ${PRODUCT_NAME} 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1.0 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIRequiresFullScreen 28 | 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | -------------------------------------------------------------------------------- /demo/app/App_Resources/iOS/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /demo/app/App_Resources/iOS/build.xcconfig: -------------------------------------------------------------------------------- 1 | // You can add custom settings here 2 | // for example you can uncomment the following line to force distribution code signing 3 | // CODE_SIGN_IDENTITY = iPhone Distribution 4 | // To build for device with XCode 8 you need to specify your development team. More info: https://developer.apple.com/library/prerelease/content/releasenotes/DeveloperTools/RN-Xcode/Introduction.html 5 | // DEVELOPMENT_TEAM = YOUR_TEAM_ID; 6 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 7 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 8 | 9 | DEVELOPMENT_TEAM = 9832T735TV 10 | -------------------------------------------------------------------------------- /demo/app/app.css: -------------------------------------------------------------------------------- 1 | #dd 2 | { 3 | padding: 5; 4 | background-color: red; 5 | color: yellow; 6 | font-size: 25; 7 | font-weight: bold; 8 | font-style: italic; 9 | text-align: center; 10 | opacity: 0.5; 11 | } -------------------------------------------------------------------------------- /demo/app/app.ts: -------------------------------------------------------------------------------- 1 | import "./bundle-config"; 2 | 3 | import application = require("application"); 4 | import * as purchase from "nativescript-purchase"; 5 | 6 | purchase.init([ 7 | "com.tangrainc.purchasesample.Product1", 8 | "com.tangrainc.purchasesample.Product2", 9 | "com.tangrainc.purchasesample.Sub1", 10 | "com.tangrainc.purchasesample.Sub2", 11 | "com.tangrainc.purcahsesample.Seasonal", 12 | ]); 13 | 14 | application.start({ moduleName: "main-page" }); 15 | -------------------------------------------------------------------------------- /demo/app/bundle-config.ts: -------------------------------------------------------------------------------- 1 | if ((global as any).TNS_WEBPACK) { 2 | // registers tns-core-modules UI framework modules 3 | // tslint:disable-next-line:no-var-requires 4 | require("bundle-entry-points"); 5 | 6 | // Views 7 | global.registerModule("main-page", () => require("./main-page")); 8 | } 9 | -------------------------------------------------------------------------------- /demo/app/main-page.ts: -------------------------------------------------------------------------------- 1 | import * as observable from "data/observable"; 2 | import * as observableArray from "data/observable-array"; 3 | import * as pages from "ui/page"; 4 | import * as purchase from "nativescript-purchase"; 5 | import { Transaction, TransactionState } from "nativescript-purchase/transaction"; 6 | import { Product } from "nativescript-purchase/product"; 7 | import { ItemEventData } from "ui/list-view"; 8 | 9 | var viewModel: observable.Observable; 10 | 11 | export function pageLoaded(args: observable.EventData) { 12 | var page = args.object; 13 | var items = new observableArray.ObservableArray(); 14 | 15 | viewModel = new observable.Observable(); 16 | 17 | purchase.on(purchase.transactionUpdatedEvent, (transaction: Transaction) => { 18 | console.log(JSON.stringify(transaction)); 19 | 20 | if (transaction.transactionState === TransactionState.Restored) { 21 | console.log(transaction.originalTransaction.transactionDate); 22 | } 23 | else if (transaction.transactionState === TransactionState.Purchased && transaction.productIdentifier.indexOf(".consume") >= 0) { 24 | purchase.consumePurchase(transaction.transactionReceipt) 25 | .then((responseCode) => console.log(responseCode)) 26 | .catch((e) => console.log(e)); 27 | } 28 | }); 29 | 30 | purchase.getProducts() 31 | .then((res) => { 32 | viewModel.set("items", res); 33 | }) 34 | .catch((e) => alert(e)); 35 | 36 | page.bindingContext = viewModel; 37 | } 38 | 39 | export function onProductTap(data: ItemEventData) { 40 | let product = viewModel.get("items")[data.index] as Product; 41 | 42 | purchase.buyProduct(product); 43 | } 44 | 45 | export function onRestoreTap() { 46 | purchase.restorePurchases(); 47 | } 48 | 49 | export function onRefreshTap() { 50 | purchase.refreshStoreReceipt(); 51 | } 52 | -------------------------------------------------------------------------------- /demo/app/main-page.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /demo/app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tns-template-hello-world-ts", 3 | "main": "app.js", 4 | "version": "1.2.0", 5 | "author": "Telerik ", 6 | "description": "Nativescript hello-world-ts project template", 7 | "license": "BSD", 8 | "keywords": [ 9 | "telerik", 10 | "mobile", 11 | "nativescript", 12 | "{N}", 13 | "tns", 14 | "appbuilder", 15 | "template" 16 | ], 17 | "repository": { 18 | "url": "https://github.com/NativeScript/NativeScript/commit/06ddbf133a1c022a9ec61dc442d7f7ce0841c915" 19 | } 20 | } -------------------------------------------------------------------------------- /demo/app/vendor-platform.android.ts: -------------------------------------------------------------------------------- 1 | require("application"); 2 | if (!global["__snapshot"]) { 3 | // In case snapshot generation is enabled these modules will get into the bundle 4 | // but will not be required/evaluated. 5 | // The snapshot webpack plugin will add them to the tns-java-classes.js bundle file. 6 | // This way, they will be evaluated on app start as early as possible. 7 | require("ui/frame"); 8 | require("ui/frame/activity"); 9 | } 10 | -------------------------------------------------------------------------------- /demo/app/vendor-platform.ios.ts: -------------------------------------------------------------------------------- 1 | // There is a bug in angular: https://github.com/angular/angular-cli/pull/8589/files 2 | // Legendary stuff, its webpack plugin pretty much doesn't work with empty TypeScript files in v1.8.3 3 | void 0; 4 | -------------------------------------------------------------------------------- /demo/app/vendor.ts: -------------------------------------------------------------------------------- 1 | // Snapshot the ~/app.css and the theme 2 | const application = require("application"); 3 | require("ui/styling/style-scope"); 4 | const appCssContext = require.context("~/", false, /^\.\/app\.(css|scss|less|sass)$/); 5 | global.registerWebpackModules(appCssContext); 6 | application.loadAppCss(); 7 | 8 | require("./vendor-platform"); 9 | 10 | require("bundle-entry-points"); 11 | -------------------------------------------------------------------------------- /demo/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "nativescript": { 3 | "id": "com.tangrainc.purchasesample", 4 | "tns-android": { 5 | "version": "4.0.1" 6 | }, 7 | "tns-ios": { 8 | "version": "4.0.1" 9 | } 10 | }, 11 | "scripts": { 12 | "android": "npm uninstall nativescript-purchase && tns deploy android", 13 | "ios": "npm uninstall nativescript-purchase && tns deploy ios", 14 | "android-release": "tns build android --release --key-store-path ~/Documents/TangraInc.keystore --key-store-password P@ssw0rd --key-store-alias \"tangra inc.\" --key-store-alias-password P@ssw0rd --copy-to ~/Documents/ApplicationDistribution/" 15 | }, 16 | "dependencies": { 17 | "nativescript-purchase": "file:../bin/dist", 18 | "tns-core-modules": "~4.0.1" 19 | }, 20 | "devDependencies": { 21 | "awesome-typescript-loader": "~3.1.3", 22 | "babel-traverse": "6.26.0", 23 | "babel-types": "6.26.0", 24 | "babylon": "6.18.0", 25 | "clean-webpack-plugin": "~0.1.19", 26 | "copy-webpack-plugin": "~4.3.0", 27 | "css-loader": "~0.28.7", 28 | "extract-text-webpack-plugin": "~3.0.2", 29 | "lazy": "1.0.11", 30 | "nativescript-css-loader": "~0.26.0", 31 | "nativescript-dev-typescript": "^0.7.1", 32 | "nativescript-dev-webpack": "^0.11.0", 33 | "nativescript-worker-loader": "~0.8.1", 34 | "raw-loader": "~0.5.1", 35 | "resolve-url-loader": "~2.2.1", 36 | "tns-platform-declarations": "^3.2.0", 37 | "typescript": "~2.2.1", 38 | "uglifyjs-webpack-plugin": "~1.1.6", 39 | "webpack": "~3.10.0", 40 | "webpack-bundle-analyzer": "^2.9.1", 41 | "webpack-sources": "~1.1.0" 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /demo/references.d.ts: -------------------------------------------------------------------------------- 1 | /// Needed for autocompletion and compilation. 2 | /// -------------------------------------------------------------------------------- /demo/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "es5", 5 | "experimentalDecorators": true, 6 | "noEmitHelpers": true, 7 | "lib": [ 8 | "es6", 9 | "dom" 10 | ], 11 | "baseUrl": ".", 12 | "paths": { 13 | "*": [ 14 | "./node_modules/tns-core-modules/*", 15 | "./node_modules/*" 16 | ], 17 | "~/*": [ 18 | "app/*" 19 | ] 20 | } 21 | }, 22 | "exclude": [ 23 | "node_modules", 24 | "platforms" 25 | ] 26 | } -------------------------------------------------------------------------------- /demo/webpack.config.js: -------------------------------------------------------------------------------- 1 | const { relative, resolve, join } = require("path"); 2 | 3 | const webpack = require("webpack"); 4 | const nsWebpack = require("nativescript-dev-webpack"); 5 | const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target"); 6 | const CleanWebpackPlugin = require("clean-webpack-plugin"); 7 | const CopyWebpackPlugin = require("copy-webpack-plugin"); 8 | const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer"); 9 | const { NativeScriptWorkerPlugin } = require("nativescript-worker-loader/NativeScriptWorkerPlugin"); 10 | const UglifyJsPlugin = require("uglifyjs-webpack-plugin"); 11 | 12 | module.exports = env => { 13 | const platform = env && (env.android && "android" || env.ios && "ios"); 14 | if (!platform) { 15 | throw new Error("You need to provide a target platform!"); 16 | } 17 | 18 | const platforms = ["ios", "android"]; 19 | const projectRoot = __dirname; 20 | nsWebpack.loadAdditionalPlugins({ projectDir: projectRoot }); 21 | 22 | // Default destination inside platforms//... 23 | const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot)); 24 | const appResourcesPlatformDir = platform === "android" ? "Android" : "iOS"; 25 | 26 | const { 27 | // The 'appPath' and 'appResourcesPath' values are fetched from 28 | // the nsconfig.json configuration file 29 | // when bundling with `tns run android|ios --bundle`. 30 | appPath = "app", 31 | appResourcesPath = "app/App_Resources", 32 | 33 | // Snapshot, uglify and report can be enabled by providing 34 | // the `--env.snapshot`, `--env.uglify` or `--env.report` flags 35 | // when running 'tns run android|ios' 36 | snapshot, 37 | uglify, 38 | report, 39 | } = env; 40 | 41 | const appFullPath = resolve(projectRoot, appPath); 42 | const appResourcesFullPath = resolve(projectRoot, appResourcesPath); 43 | 44 | const config = { 45 | context: appFullPath, 46 | watchOptions: { 47 | ignored: [ 48 | appResourcesFullPath, 49 | // Don't watch hidden files 50 | "**/.*", 51 | ] 52 | }, 53 | target: nativescriptTarget, 54 | entry: { 55 | bundle: `./${nsWebpack.getEntryModule(appFullPath)}`, 56 | vendor: "./vendor" 57 | }, 58 | output: { 59 | pathinfo: true, 60 | path: dist, 61 | libraryTarget: "commonjs2", 62 | filename: "[name].js", 63 | }, 64 | resolve: { 65 | extensions: [".ts", ".js", ".scss", ".css"], 66 | // Resolve {N} system modules from tns-core-modules 67 | modules: [ 68 | "node_modules/tns-core-modules", 69 | "node_modules", 70 | ], 71 | alias: { 72 | '~': resolve("./app") 73 | }, 74 | // don't resolve symlinks to symlinked modules 75 | symlinks: false 76 | }, 77 | resolveLoader: { 78 | // don't resolve symlinks to symlinked loaders 79 | symlinks: false 80 | }, 81 | node: { 82 | // Disable node shims that conflict with NativeScript 83 | "http": false, 84 | "timers": false, 85 | "setImmediate": false, 86 | "fs": "empty", 87 | }, 88 | module: { 89 | rules: [ 90 | { test: /\.(html|xml)$/, use: "raw-loader" }, 91 | 92 | { 93 | test: /\.css$/, 94 | use: { loader: "css-loader", options: { minimize: false, url: false } } 95 | }, 96 | 97 | { 98 | test: /\.scss$/, 99 | use: [ 100 | { loader: "css-loader", options: { minimize: false, url: false } }, 101 | "sass-loader" 102 | ] 103 | }, 104 | 105 | { test: /\.ts$/, use: "awesome-typescript-loader" } 106 | ] 107 | }, 108 | plugins: [ 109 | // Vendor libs go to the vendor.js chunk 110 | new webpack.optimize.CommonsChunkPlugin({ 111 | name: ["vendor"], 112 | }), 113 | // Define useful constants like TNS_WEBPACK 114 | new webpack.DefinePlugin({ 115 | "global.TNS_WEBPACK": "true", 116 | }), 117 | // Remove all files from the out dir. 118 | new CleanWebpackPlugin([ `${dist}/**/*` ]), 119 | // Copy native app resources to out dir. 120 | new CopyWebpackPlugin([ 121 | { 122 | from: `${appResourcesFullPath}/${appResourcesPlatformDir}`, 123 | to: `${dist}/App_Resources/${appResourcesPlatformDir}`, 124 | context: projectRoot 125 | }, 126 | ]), 127 | // Copy assets to out dir. Add your own globs as needed. 128 | new CopyWebpackPlugin([ 129 | { from: "fonts/**" }, 130 | { from: "**/*.jpg" }, 131 | { from: "**/*.png" }, 132 | { from: "**/*.xml" }, 133 | ], { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] }), 134 | // Generate a bundle starter script and activate it in package.json 135 | new nsWebpack.GenerateBundleStarterPlugin([ 136 | "./vendor", 137 | "./bundle", 138 | ]), 139 | // Support for web workers since v3.2 140 | new NativeScriptWorkerPlugin(), 141 | new nsWebpack.PlatformFSPlugin({ 142 | platform, 143 | platforms, 144 | }), 145 | // Does IPC communication with the {N} CLI to notify events when running in watch mode. 146 | new nsWebpack.WatchStateLoggerPlugin(), 147 | ], 148 | }; 149 | if (report) { 150 | // Generate report files for bundles content 151 | config.plugins.push(new BundleAnalyzerPlugin({ 152 | analyzerMode: "static", 153 | openAnalyzer: false, 154 | generateStatsFile: true, 155 | reportFilename: resolve(projectRoot, "report", `report.html`), 156 | statsFilename: resolve(projectRoot, "report", `stats.json`), 157 | })); 158 | } 159 | if (snapshot) { 160 | config.plugins.push(new nsWebpack.NativeScriptSnapshotPlugin({ 161 | chunk: "vendor", 162 | projectRoot, 163 | webpackConfig: config, 164 | targetArchs: ["arm", "arm64", "ia32"], 165 | tnsJavaClassesOptions: { packages: ["tns-core-modules" ] }, 166 | useLibs: false 167 | })); 168 | } 169 | if (uglify) { 170 | config.plugins.push(new webpack.LoaderOptionsPlugin({ minimize: true })); 171 | 172 | // Work around an Android issue by setting compress = false 173 | const compress = platform !== "android"; 174 | config.plugins.push(new UglifyJsPlugin({ 175 | uglifyOptions: { 176 | mangle: { reserved: nsWebpack.uglifyMangleExcludes }, // Deprecated. Remove if using {N} 4+. 177 | compress, 178 | } 179 | })); 180 | } 181 | return config; 182 | }; 183 | -------------------------------------------------------------------------------- /gruntfile.js: -------------------------------------------------------------------------------- 1 | module.exports = function (grunt) { 2 | var localConfig = { 3 | typeScriptSrc: [ 4 | "**/*.ts", 5 | "!node_modules/**/*.*", 6 | "!demo/**/*.*", 7 | "!bin/**/*.*" 8 | ], 9 | typeScriptDeclarations: [ 10 | "**/*.d.ts", 11 | "!references.d.ts", 12 | "!typings/*.*", 13 | "!node_modules/**/*.*", 14 | "!demo/**/*.*", 15 | "!bin/**/*.*" 16 | ], 17 | outDir: "bin/dist/" 18 | } 19 | 20 | grunt.initConfig({ 21 | clean: { 22 | build: { 23 | src: [localConfig.outDir] 24 | } 25 | }, 26 | ts: { 27 | build: { 28 | tsconfig: true 29 | } 30 | }, 31 | tslint: 32 | { 33 | build: 34 | { 35 | src: localConfig.typeScriptSrc.concat(["!typings/*.*"]), 36 | options: { 37 | configuration: grunt.file.readJSON("./tslint.json") 38 | } 39 | } 40 | }, 41 | copy: { 42 | declarations: { 43 | files: [{ expand: true, src: localConfig.typeScriptDeclarations, dest: localConfig.outDir }] 44 | }, 45 | subPackageConfig: { 46 | files: [{ expand: true, src: ["*/package.json", "!demo/**"], dest: localConfig.outDir }] 47 | }, 48 | platforms: { 49 | files: [{ expand: true, src: ["platforms/**"], dest: localConfig.outDir }] 50 | }, 51 | packageConfig: { 52 | src: "package.json", 53 | dest: localConfig.outDir, 54 | options: { 55 | process: function (content, srcPath) { 56 | var contentAsObject = JSON.parse(content); 57 | contentAsObject.devDependencies = undefined; 58 | return JSON.stringify(contentAsObject, null, "\t"); 59 | } 60 | } 61 | }, 62 | readme: { 63 | src: "README.md", 64 | dest: localConfig.outDir, 65 | options: { 66 | process: function (content, srcPath) { 67 | return content.substring(content.indexOf("\n") + 1) 68 | } 69 | } 70 | }, 71 | android_aar: { 72 | src: "android/inappbilling/inappbillinghelper/build/outputs/aar/inappbillinghelper-release.aar", 73 | dest: localConfig.outDir + "platforms/android/inappbillinghelper-release.aar" 74 | } 75 | }, 76 | exec: { 77 | tsCompile: { 78 | cmd: "./node_modules/.bin/tsc --project tsconfig.json --outDir " + localConfig.outDir 79 | }, 80 | tslint: { 81 | cmd: "./node_modules/.bin/tslint --project tsconfig.json --type-check" 82 | }, 83 | checkRequiredReadmeSection: { 84 | cwd: "bin/dist", 85 | cmd: function (section) { 86 | return "cat README.md | grep -q \"# " + section + "\""; 87 | } 88 | }, 89 | checkRequiredPackageJsonSection: { 90 | cwd: "bin/dist", 91 | cmd: function (section) { 92 | return "cat package.json | grep -q \"\\\"" + section + "\\\"\""; 93 | } 94 | }, 95 | "ci-build-demo": { 96 | cmd: function (platform, demoSuffix) { 97 | return "cd demo" + (demoSuffix != "" ? "-" + demoSuffix : "") + " && npm install && tns build " + platform; 98 | } 99 | }, 100 | "ci-webpack-demo": { 101 | cmd: function (platform, demoSuffix) { 102 | return "cd demo" + (demoSuffix != "" ? "-" + demoSuffix : "")+ " && npm install && tns build " + platform + " --bundle --env.uglify --env.snapshot"; 103 | } 104 | }, 105 | build_android_aar: { 106 | cmd: "./gradlew build", 107 | cwd: "android/inappbilling/" 108 | }, 109 | npm_publish: { 110 | cmd: "npm publish", 111 | cwd: localConfig.outDir 112 | }, 113 | } 114 | }); 115 | 116 | grunt.loadNpmTasks("grunt-contrib-copy"); 117 | grunt.loadNpmTasks("grunt-contrib-clean"); 118 | grunt.loadNpmTasks("grunt-exec"); 119 | 120 | grunt.registerTask("compile", function () { 121 | var tasks = [ 122 | "clean:build", 123 | "exec:tsCompile", 124 | "copy" 125 | ]; 126 | if (!process.env.iOS) { 127 | tasks.splice(2, 0, "exec:build_android_aar"); 128 | } 129 | 130 | grunt.task.run(tasks); 131 | }); 132 | 133 | grunt.registerTask("build", [ 134 | "exec:tslint", 135 | "compile", 136 | "copy" 137 | ]); 138 | 139 | grunt.registerTask("ci", "Performs CI builds for the demo projects", function (action, platform) { 140 | if (!platform || platform === "") { 141 | grunt.warn("You must specify a platform (ios or android)!"); 142 | } 143 | if (!action || action === "") { 144 | grunt.warn("You must specify an action (build or webpack)!"); 145 | } 146 | 147 | var baseTask = "exec:ci-" + action.toLowerCase() + "-demo:" + platform.toLowerCase(); 148 | grunt.task.run( 149 | baseTask + ":" 150 | // baseTask + ":ng" 151 | ); 152 | }); 153 | 154 | grunt.registerTask("lint", [ 155 | "exec:checkRequiredReadmeSection:Installation", 156 | "exec:checkRequiredReadmeSection:Configuration", 157 | "exec:checkRequiredReadmeSection:API", 158 | "exec:checkRequiredReadmeSection:Usage", 159 | "exec:checkRequiredPackageJsonSection:license", 160 | "exec:checkRequiredPackageJsonSection:nativescript", 161 | "exec:tslint", 162 | ]); 163 | 164 | grunt.registerTask("publish", [ 165 | "build", 166 | "lint", 167 | "exec:npm_publish" 168 | ]); 169 | }; -------------------------------------------------------------------------------- /nativescript-purchase.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nativescript-purchase", 3 | "version": "2.0.14", 4 | "description": "A NativeScript plugin for making in-app purchases", 5 | "main": "purchase", 6 | "typings": "nativescript-purchase.d.ts", 7 | "nativescript": { 8 | "platforms": { 9 | "ios": "3.0.0", 10 | "android": "3.0.0" 11 | }, 12 | "plugin": { 13 | "nan": "true", 14 | "pan": "true", 15 | "core3": "true", 16 | "category": "Utilities" 17 | } 18 | }, 19 | "repository": { 20 | "type": "git", 21 | "url": "https://github.com/PeterStaev/nativescript-purchase" 22 | }, 23 | "keywords": [ 24 | "NativeScript", 25 | "iap", 26 | "in-app purchase", 27 | "in-app billing", 28 | "vending", 29 | "payment", 30 | "subscription", 31 | "tangra" 32 | ], 33 | "author": "Peter Staev ", 34 | "contributors": [ 35 | "Sven Ziegler (https://github.com/svzi)", 36 | "Yoann Wackers (https://github.com/Heer0)", 37 | "Royi Namir (https://github.com/RoyiNamir)" 38 | ], 39 | "license": "Apache-2.0", 40 | "peerDependencies": { 41 | "tns-core-modules": ">=3" 42 | }, 43 | "devDependencies": { 44 | "tns-core-modules": "^3.0.0", 45 | "tns-platform-declarations": "3.4.0", 46 | "tslint": "^4.5.1", 47 | "typescript": "~2.2.2", 48 | "grunt": "1.0.1", 49 | "grunt-contrib-copy": "1.0.0", 50 | "grunt-contrib-clean": "1.0.0", 51 | "grunt-exec": "2.0.0" 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /platforms/android/include.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | compile "com.google.guava:guava:18.0" 3 | } -------------------------------------------------------------------------------- /product/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "product", 3 | "main": "product" 4 | } 5 | -------------------------------------------------------------------------------- /product/product-common.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) 2019 Tangra Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ***************************************************************************** */ 16 | 17 | import * as definition from "nativescript-purchase/product"; 18 | 19 | export { ProductType } from "nativescript-purchase/product"; 20 | 21 | export class ProductBase implements definition.Product { 22 | public nativeValue: any; 23 | 24 | public productIdentifier: string; 25 | public localizedTitle: string; 26 | public localizedDescription: string; 27 | public priceAmount: number; 28 | public priceFormatted: string; 29 | public priceCurrencyCode: string; 30 | public productType: definition.ProductType; 31 | public subscriptionPeriod?: string; 32 | 33 | constructor(nativeValue: any, type?: definition.ProductType) { 34 | this.nativeValue = nativeValue; 35 | this.productType = type; 36 | } 37 | } -------------------------------------------------------------------------------- /product/product.android.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) 2019 Tangra Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ***************************************************************************** */ 16 | 17 | import { ProductBase, ProductType} from "./product-common"; 18 | 19 | export * from "./product-common"; 20 | 21 | export class Product extends ProductBase { 22 | constructor(nativeValue: org.json.JSONObject, type: ProductType) { 23 | super(nativeValue, type); 24 | 25 | this.productIdentifier = nativeValue.getString("productId"); 26 | this.localizedDescription = nativeValue.getString("description"); 27 | this.localizedTitle = nativeValue.getString("title"); 28 | this.priceAmount = nativeValue.getLong("price_amount_micros") / 1000000; 29 | this.priceFormatted = nativeValue.getString("price"); 30 | this.priceCurrencyCode = nativeValue.getString("price_currency_code"); 31 | if (nativeValue.has("subscriptionPeriod")) { 32 | this.subscriptionPeriod = nativeValue.getString("subscriptionPeriod"); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /product/product.d.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) 2019 Tangra Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ***************************************************************************** */ 16 | 17 | declare module "nativescript-purchase/product" { 18 | export type ProductType = "inapp" | "subs"; 19 | 20 | export class Product { 21 | public nativeValue: any; 22 | 23 | public productIdentifier: string; 24 | public localizedTitle: string; 25 | public localizedDescription: string; 26 | public priceAmount: number; 27 | public priceFormatted: string; 28 | public priceCurrencyCode: string; 29 | public productType: ProductType; 30 | public subscriptionPeriod?: string; 31 | 32 | constructor(nativeValue: any, type?: ProductType); 33 | } 34 | } -------------------------------------------------------------------------------- /product/product.ios.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) 2019 Tangra Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ***************************************************************************** */ 16 | 17 | import { ProductBase, ProductType} from "./product-common"; 18 | 19 | export * from "./product-common"; 20 | 21 | const unitsAsString = ["D", "W", "M", "Y"]; 22 | 23 | export class Product extends ProductBase { 24 | constructor(nativeValue: SKProduct, type: ProductType) { 25 | super(nativeValue, type); 26 | 27 | const formatter = NSNumberFormatter.alloc().init(); 28 | formatter.numberStyle = NSNumberFormatterStyle.CurrencyStyle; 29 | formatter.locale = nativeValue.priceLocale; 30 | 31 | this.productIdentifier = nativeValue.productIdentifier; 32 | this.localizedDescription = nativeValue.localizedDescription; 33 | this.localizedTitle = nativeValue.localizedTitle; 34 | this.priceAmount = nativeValue.price.doubleValue; 35 | this.priceFormatted = formatter.stringFromNumber(nativeValue.price as any); 36 | this.priceCurrencyCode = nativeValue.priceLocale.objectForKey(NSLocaleCurrencyCode); 37 | 38 | // NOTE: The following code will can ONLY on ios 11.2 as the subscriptionPeriod property is a new one 39 | const subscriptionPeriod = (nativeValue as any).subscriptionPeriod; 40 | if (subscriptionPeriod) { 41 | if (subscriptionPeriod.numberOfUnits > 0) { 42 | this.productType = "subs"; 43 | this.subscriptionPeriod = `P${subscriptionPeriod.numberOfUnits}${unitsAsString[subscriptionPeriod.unit]}`; 44 | } 45 | else { 46 | this.productType = "inapp"; 47 | } 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /purchase-common.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) 2019 Tangra Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ***************************************************************************** */ 16 | 17 | let observers: { [eventName: string]: Array<(data: any) => void> } = {}; 18 | 19 | export const transactionUpdatedEvent = "transactionUpdated"; 20 | 21 | export function _notify(eventName: string, data: any) { 22 | if (!observers[eventName]) { 23 | return; 24 | } 25 | 26 | observers[eventName].forEach((callback) => { callback(data); }); 27 | } 28 | 29 | export function on(eventName: string, handler: (data: any) => void) { 30 | if (!observers[eventName]) { 31 | observers[eventName] = []; 32 | } 33 | 34 | observers[eventName].push(handler); 35 | } 36 | 37 | export function off(eventName: string, handler?: (data: any) => void) { 38 | if (!observers[eventName]) { 39 | return; 40 | } 41 | 42 | if (!handler) { 43 | observers[eventName].splice(0); 44 | return; 45 | } 46 | 47 | let index = observers[eventName].indexOf(handler); 48 | if (index !== -1) { 49 | observers[eventName].splice(index, 1); 50 | } 51 | } 52 | 53 | export function getStoreReceipt(): string { 54 | return undefined; 55 | } -------------------------------------------------------------------------------- /purchase.android.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) 2019 Tangra Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ***************************************************************************** */ 16 | 17 | import * as common from "./purchase-common"; 18 | import * as application from "application"; 19 | import * as types from "utils/types"; 20 | import { Product } from "nativescript-purchase/product"; 21 | import { Transaction, TransactionState } from "nativescript-purchase/transaction"; 22 | 23 | export * from "./purchase-common"; 24 | 25 | let helper: com.tangrainc.inappbilling.InAppBillingHelper; 26 | let currentBuyPayload: string; 27 | let currentBuyProductIdentifier: string; 28 | 29 | export function init(productIdentifiers: Array): Promise { 30 | return new Promise((resolve, reject) => { 31 | const nativeArray = Array.create(java.lang.String, productIdentifiers.length); 32 | for (let loop = 0; loop < productIdentifiers.length; loop++) { 33 | nativeArray[loop] = productIdentifiers[loop].toLowerCase(); // Android product IDs are all lower case 34 | } 35 | 36 | ensureApplicationContext().then(() => { 37 | helper = new com.tangrainc.inappbilling.InAppBillingHelper(application.android.context, nativeArray); 38 | resolve(); 39 | }); 40 | 41 | application.android.on(application.AndroidApplication.activityResultEvent, (args: application.AndroidActivityResultEventData) => { 42 | if (args.requestCode === com.tangrainc.inappbilling.InAppBillingHelper.BUY_INTENT_REQUEST_CODE) { 43 | const intent = args.intent as android.content.Intent; 44 | let tran: Transaction; 45 | 46 | if (intent) { 47 | const responseCode = intent.getIntExtra("RESPONSE_CODE", 0); 48 | const purchaseData = intent.getStringExtra("INAPP_PURCHASE_DATA"); 49 | const dataSignature = intent.getStringExtra("INAPP_DATA_SIGNATURE"); 50 | 51 | if (args.resultCode === android.app.Activity.RESULT_OK && responseCode === 0 && !types.isNullOrUndefined(purchaseData)) { 52 | const nativeValue = new org.json.JSONObject(purchaseData); 53 | nativeValue.put("signature", dataSignature); 54 | tran = new Transaction(nativeValue); 55 | } 56 | else { 57 | tran = getFailedTransaction(); 58 | } 59 | } 60 | else { 61 | tran = getFailedTransaction(); 62 | } 63 | 64 | common._notify(common.transactionUpdatedEvent, tran); 65 | } 66 | }); 67 | }); 68 | } 69 | 70 | export function getProducts(): Promise> { 71 | return new Promise>((resolve, reject) => { 72 | Promise.all([ 73 | futureToPromise(helper.getProducts("inapp")), 74 | futureToPromise(helper.getProducts("subs")), 75 | ]) 76 | .then((result: Array>) => { 77 | const productArray: Array = []; 78 | for (let type = 0; type <= 1; type++) { 79 | for (const item of result[type]) { 80 | productArray.push(new Product(item, (type === 0 ? "inapp" : "subs"))); 81 | } 82 | } 83 | 84 | resolve(productArray); 85 | }) 86 | .catch(reject); 87 | }); 88 | } 89 | 90 | export function buyProduct(product: Product, developerPayload?: string) { 91 | const tran = new Transaction(null); 92 | tran.transactionState = TransactionState.Purchasing; 93 | tran.productIdentifier = product.productIdentifier; 94 | tran.developerPayload = developerPayload; 95 | common._notify(common.transactionUpdatedEvent, tran); 96 | 97 | currentBuyProductIdentifier = product.productIdentifier; 98 | currentBuyPayload = developerPayload; 99 | 100 | helper.startBuyIntent(application.android.foregroundActivity, 101 | product.productIdentifier, 102 | product.productType, 103 | developerPayload || ""); 104 | } 105 | 106 | export function consumePurchase(token: string): Promise { 107 | return new Promise((resolve, reject) => { 108 | futureToPromise(helper.consumePurchase(token)).then(resolve, reject); 109 | }); 110 | } 111 | 112 | export function restorePurchases(): Promise { 113 | return Promise.all([ 114 | futureToPromise(helper.getPurchases(null, "inapp")), 115 | futureToPromise(helper.getPurchases(null, "subs")) 116 | ]).then((result: Array>) => { 117 | for (let type = 0; type <= 1; type++) { 118 | for (const item of result[type]) { 119 | const tran = new Transaction(null); 120 | tran.originalTransaction = new Transaction(item); 121 | tran.transactionState = TransactionState.Restored; 122 | 123 | common._notify(common.transactionUpdatedEvent, tran); 124 | } 125 | } 126 | }); 127 | } 128 | 129 | export function canMakePayments(): boolean { 130 | return true; 131 | } 132 | 133 | export function getStoreReceipt(): string { 134 | return null; 135 | } 136 | 137 | export function refreshStoreReceipt(): Promise { 138 | return Promise.resolve(); 139 | } 140 | 141 | function getFailedTransaction() { 142 | const tran = new Transaction(null); 143 | tran.transactionState = TransactionState.Failed; 144 | tran.productIdentifier = currentBuyProductIdentifier; 145 | tran.developerPayload = currentBuyPayload; 146 | 147 | return tran; 148 | } 149 | 150 | function futureToPromise(future: any /* ListenableFuture */): Promise { 151 | return new Promise((resolve, reject) => { 152 | com.google.common.util.concurrent.Futures.addCallback( 153 | future, 154 | new com.google.common.util.concurrent.FutureCallback({ 155 | onSuccess: (result) => { 156 | resolve(result); 157 | } 158 | , onFailure: (t /* Throwable */) => { 159 | reject(new Error(t.getMessage())); 160 | } 161 | }), 162 | com.google.common.util.concurrent.MoreExecutors.directExecutor(), 163 | ); 164 | }); 165 | } 166 | 167 | function ensureApplicationContext(): Promise { 168 | return new Promise((resolve, reject) => { 169 | if (application.android && application.android.context) { 170 | resolve(); 171 | return; 172 | } 173 | 174 | application.on(application.launchEvent, (args: application.LaunchEventData) => { 175 | resolve(); 176 | }); 177 | }); 178 | } 179 | -------------------------------------------------------------------------------- /purchase.d.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) 2019 Tangra Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ***************************************************************************** */ 16 | 17 | declare module "nativescript-purchase" { 18 | import { Product } from "nativescript-purchase/product"; 19 | import { Transaction } from "nativescript-purchase/transaction"; 20 | 21 | export const transactionUpdatedEvent: string; 22 | 23 | export function init(productIdentifiers: Array): Promise; 24 | export function getProducts(): Promise>; 25 | export function buyProduct(product: Product, developerPayload?: string); 26 | export function consumePurchase(token: string): Promise; 27 | export function restorePurchases(): Promise; 28 | export function canMakePayments(): boolean; 29 | export function getStoreReceipt(): string; 30 | export function refreshStoreReceipt(): Promise; 31 | 32 | export function on(eventName: string, handler: (data: any) => void); 33 | export function on(eventName: "transactionUpdated", handler: (data: Transaction) => void); 34 | 35 | export function off(eventName: string, handler?: (data: any) => void); 36 | export function off(eventName: "transactionUpdated", handler?: (data: Transaction) => void); 37 | } 38 | -------------------------------------------------------------------------------- /purchase.ios.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) 2019 Tangra Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ***************************************************************************** */ 16 | 17 | import { Product } from "nativescript-purchase/product"; 18 | import { Transaction } from "nativescript-purchase/transaction"; 19 | import * as common from "./purchase-common"; 20 | 21 | export * from "./purchase-common"; 22 | 23 | let productRequest: SKProductsRequest; 24 | let productIds: NSMutableSet; 25 | let productRequestDelegate: SKProductRequestDelegateImpl; 26 | let paymentTransactionObserver: SKPaymentTransactionObserverImpl; 27 | let storedDeveloperPayload: string; 28 | let refreshReceiptRequest: SKReceiptRefreshRequest; 29 | let refreshReceiptRequestDelegate: SKReceiptRefreshRequestDelegateImpl; 30 | 31 | export function init(productIdentifiers: Array): Promise { 32 | return new Promise((resolve, reject) => { 33 | productIds = NSMutableSet.alloc().init(); 34 | paymentTransactionObserver = new SKPaymentTransactionObserverImpl(); 35 | 36 | productIdentifiers.forEach((value) => productIds.addObject(value)); 37 | 38 | SKPaymentQueue.defaultQueue().addTransactionObserver(paymentTransactionObserver); 39 | resolve(); 40 | }); 41 | } 42 | 43 | export function getProducts(): Promise> { 44 | return new Promise((resolve, reject) => { 45 | productRequest = SKProductsRequest.alloc().initWithProductIdentifiers(productIds); 46 | productRequestDelegate = SKProductRequestDelegateImpl.initWithResolveReject(resolve, reject); 47 | productRequest.delegate = productRequestDelegate; 48 | productRequest.start(); 49 | }); 50 | } 51 | 52 | export function buyProduct(product: Product, developerPayload?: string) { 53 | if (!product.nativeValue) { 54 | throw "Invalid Product! (missing native value)"; 55 | } 56 | 57 | storedDeveloperPayload = developerPayload; 58 | 59 | const payment = SKPayment.paymentWithProduct(product.nativeValue); 60 | SKPaymentQueue.defaultQueue().addPayment(payment); 61 | } 62 | 63 | export function consumePurchase(token: string): Promise { 64 | return new Promise((resolve, reject) => { 65 | resolve(0); 66 | }); 67 | } 68 | 69 | export function restorePurchases(): Promise { 70 | SKPaymentQueue.defaultQueue().restoreCompletedTransactions(); 71 | return Promise.resolve(); 72 | } 73 | 74 | export function canMakePayments(): boolean { 75 | return SKPaymentQueue.canMakePayments(); 76 | } 77 | 78 | export function getStoreReceipt(): string { 79 | const receiptData = NSData.dataWithContentsOfURL(NSBundle.mainBundle.appStoreReceiptURL); 80 | 81 | if (receiptData) { 82 | return receiptData.base64EncodedStringWithOptions(0); 83 | } 84 | else { 85 | return null; 86 | } 87 | } 88 | 89 | export function refreshStoreReceipt(): Promise { 90 | return new Promise((resolve, reject) => { 91 | refreshReceiptRequest = SKReceiptRefreshRequest.alloc().init(); 92 | refreshReceiptRequestDelegate = SKReceiptRefreshRequestDelegateImpl.initWithResolveReject(resolve, reject); 93 | refreshReceiptRequest.delegate = refreshReceiptRequestDelegate; 94 | refreshReceiptRequest.start(); 95 | }); 96 | } 97 | 98 | 99 | @ObjCClass(SKRequestDelegate) 100 | class SKReceiptRefreshRequestDelegateImpl extends NSObject implements SKRequestDelegate { 101 | private _resolve: Function; 102 | private _reject: Function; 103 | 104 | public static initWithResolveReject(resolve: Function, reject: Function): SKReceiptRefreshRequestDelegateImpl { 105 | const delegate: SKReceiptRefreshRequestDelegateImpl = SKReceiptRefreshRequestDelegateImpl.new() as SKReceiptRefreshRequestDelegateImpl; 106 | delegate._resolve = resolve; 107 | delegate._reject = reject; 108 | 109 | return delegate; 110 | } 111 | 112 | public requestDidFinish(request: SKRequest) { 113 | this._resolve(); 114 | this._cleanup(); 115 | } 116 | 117 | public requestDidFailWithError(request: SKRequest, error: NSError) { 118 | this._reject(new Error(error.localizedDescription)); 119 | this._cleanup(); 120 | } 121 | 122 | private _cleanup() { 123 | refreshReceiptRequestDelegate = null; 124 | refreshReceiptRequest = null; 125 | } 126 | } 127 | 128 | @ObjCClass(SKProductsRequestDelegate) 129 | class SKProductRequestDelegateImpl extends NSObject implements SKProductsRequestDelegate { 130 | private _resolve: Function; 131 | private _reject: Function; 132 | 133 | public static initWithResolveReject(resolve: Function, reject: Function): SKProductRequestDelegateImpl { 134 | const delegate: SKProductRequestDelegateImpl = SKProductRequestDelegateImpl.new() as SKProductRequestDelegateImpl; 135 | delegate._resolve = resolve; 136 | delegate._reject = reject; 137 | 138 | return delegate; 139 | } 140 | 141 | public productsRequestDidReceiveResponse(request: SKProductsRequest, response: SKProductsResponse) { 142 | const products = response.products; 143 | const result: Array = []; 144 | 145 | for (let loop = 0; loop < products.count; loop++) { 146 | result.push(new Product(products.objectAtIndex(loop))); 147 | } 148 | 149 | this._resolve(result); 150 | this._cleanup(); 151 | } 152 | 153 | public requestDidFailWithError(request: SKRequest, error: NSError) { 154 | this._reject(new Error(error.localizedDescription)); 155 | this._cleanup(); 156 | } 157 | 158 | private _cleanup() { 159 | productRequestDelegate = null; 160 | productRequest = null; 161 | } 162 | } 163 | 164 | @ObjCClass(SKPaymentTransactionObserver) 165 | class SKPaymentTransactionObserverImpl extends NSObject implements SKPaymentTransactionObserver { 166 | public paymentQueueUpdatedTransactions(queue: SKPaymentQueue, transactions: NSArray) { 167 | for (let loop = 0; loop < transactions.count; loop++) { 168 | const transaction = transactions.objectAtIndex(loop); 169 | let resultTransaction: Transaction = null; 170 | 171 | if (transaction) { 172 | resultTransaction = new Transaction(transaction); 173 | resultTransaction.developerPayload = storedDeveloperPayload; 174 | } 175 | 176 | common._notify(common.transactionUpdatedEvent, resultTransaction); 177 | 178 | if (transaction 179 | && (transaction.transactionState === SKPaymentTransactionState.Failed 180 | || transaction.transactionState === SKPaymentTransactionState.Purchased 181 | || transaction.transactionState === SKPaymentTransactionState.Restored)) { 182 | SKPaymentQueue.defaultQueue().finishTransaction(transaction); 183 | storedDeveloperPayload = undefined; 184 | } 185 | } 186 | } 187 | } 188 | -------------------------------------------------------------------------------- /references.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// -------------------------------------------------------------------------------- /transaction/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "transaction", 3 | "main": "transaction" 4 | } 5 | -------------------------------------------------------------------------------- /transaction/transaction-common.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) 2019 Tangra Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ***************************************************************************** */ 16 | 17 | import * as definition from "nativescript-purchase/transaction"; 18 | 19 | export class TransactionBase implements definition.Transaction { 20 | public nativeValue: any; 21 | 22 | public transactionState: string; 23 | public productIdentifier: string; 24 | public transactionIdentifier: string; 25 | public transactionDate: Date; 26 | public transactionReceipt: string; 27 | public originalTransaction: TransactionBase; 28 | public developerPayload: string; /* Android Only */ 29 | public dataSignature: string; /* Android Only */ 30 | 31 | constructor(nativeValue: any) { 32 | this.nativeValue = nativeValue; 33 | } 34 | } 35 | 36 | export class TransactionState implements definition.TransactionState { 37 | public static Purchased = "purchased"; 38 | public static Restored = "restored"; 39 | public static Failed = "failed"; 40 | public static Deferred = "deferred"; 41 | public static Purchasing = "purchasing"; 42 | public static Refunded = "refunded"; 43 | } -------------------------------------------------------------------------------- /transaction/transaction.android.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) 2019 Tangra Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ***************************************************************************** */ 16 | 17 | import { TransactionBase, TransactionState } from "./transaction-common"; 18 | 19 | export * from "./transaction-common"; 20 | 21 | export class Transaction extends TransactionBase { 22 | 23 | constructor(nativeValue: org.json.JSONObject) { 24 | super(nativeValue); 25 | 26 | if (nativeValue) { 27 | switch (nativeValue.getInt("purchaseState")) { 28 | case 0: 29 | this.transactionState = TransactionState.Purchased; 30 | break; 31 | 32 | case 1: 33 | this.transactionState = TransactionState.Failed; 34 | break; 35 | 36 | case 2: 37 | this.transactionState = TransactionState.Refunded; 38 | break; 39 | } 40 | 41 | this.productIdentifier = nativeValue.getString("productId"); 42 | this.transactionReceipt = nativeValue.getString("purchaseToken"); 43 | if (nativeValue.has("signature")) { 44 | this.dataSignature = nativeValue.getString("signature"); 45 | } 46 | if (nativeValue.has("orderId")) { 47 | this.transactionIdentifier = nativeValue.getString("orderId"); 48 | } 49 | if (nativeValue.has("developerPayload")) { 50 | this.developerPayload = nativeValue.getString("developerPayload"); 51 | } 52 | if (nativeValue.getLong("purchaseTime")) { 53 | this.transactionDate = new Date(nativeValue.getLong("purchaseTime")); 54 | } 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /transaction/transaction.d.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) 2019 Tangra Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ***************************************************************************** */ 16 | 17 | declare module "nativescript-purchase/transaction" { 18 | export class Transaction { 19 | public nativeValue: any; 20 | 21 | public transactionState: string; 22 | public productIdentifier: string; 23 | public transactionIdentifier: string; 24 | public transactionDate: Date; 25 | public transactionReceipt: string; 26 | public originalTransaction: Transaction; 27 | public developerPayload: string; 28 | public dataSignature: string; /* Android Only */ 29 | 30 | constructor(nativeValue: any); 31 | } 32 | 33 | export class TransactionState { 34 | public static Purchased: string; 35 | public static Restored: string; 36 | public static Failed: string; 37 | public static Deferred: string; 38 | public static Purchasing: string; 39 | public static Refunded: string; 40 | } 41 | } -------------------------------------------------------------------------------- /transaction/transaction.ios.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) 2019 Tangra Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ***************************************************************************** */ 16 | 17 | import { TransactionBase, TransactionState } from "./transaction-common"; 18 | 19 | export * from "./transaction-common"; 20 | 21 | export class Transaction extends TransactionBase { 22 | constructor(nativeValue: SKPaymentTransaction) { 23 | super(nativeValue); 24 | 25 | if (nativeValue.transactionState !== null) { 26 | switch (nativeValue.transactionState) { 27 | case SKPaymentTransactionState.Deferred: 28 | this.transactionState = TransactionState.Deferred; 29 | break; 30 | 31 | case SKPaymentTransactionState.Failed: 32 | this.transactionState = TransactionState.Failed; 33 | break; 34 | 35 | case SKPaymentTransactionState.Purchased: 36 | this.transactionState = TransactionState.Purchased; 37 | break; 38 | 39 | case SKPaymentTransactionState.Purchasing: 40 | this.transactionState = TransactionState.Purchasing; 41 | break; 42 | 43 | case SKPaymentTransactionState.Restored: 44 | this.transactionState = TransactionState.Restored; 45 | if (nativeValue.originalTransaction) { 46 | this.originalTransaction = new Transaction(nativeValue.originalTransaction); 47 | } 48 | break; 49 | } 50 | } 51 | 52 | if (nativeValue.payment) { 53 | this.productIdentifier = nativeValue.payment.productIdentifier; 54 | } 55 | this.transactionIdentifier = nativeValue.transactionIdentifier; 56 | if (nativeValue.transactionDate) { 57 | this.transactionDate = nativeValue.transactionDate as any; // NSDate will automatically be bridged to date 58 | } 59 | if (nativeValue.transactionReceipt) { 60 | this.transactionReceipt = nativeValue.transactionReceipt.base64EncodedStringWithOptions(NSDataBase64EncodingOptions.Encoding64CharacterLineLength); 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "noEmitOnError": true, 4 | "noEmitHelpers": true, 5 | "noUnusedLocals": true, 6 | "experimentalDecorators": true, 7 | "noLib": false, 8 | "sourceMap": false, 9 | "target": "es5", 10 | "module": "commonjs", 11 | "outDir": "bin/dist", 12 | "lib": [ 13 | "es6", 14 | "dom" 15 | ], 16 | "rootDir": ".", 17 | "baseUrl": ".", 18 | "paths": { 19 | "*": [ 20 | "./node_modules/tns-core-modules/*", 21 | "./node_modules/*" 22 | ] 23 | } 24 | }, 25 | "exclude": [ 26 | "node_modules", 27 | "demo", 28 | "bin" 29 | ] 30 | } -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rules": { 3 | "class-name": true, 4 | "comment-format": [ true, "check-space" ], 5 | "curly": true, 6 | "eofline": false, 7 | "forin": false, 8 | "indent": [ true, "spaces" ], 9 | "label-position": true, 10 | "max-line-length": [ false ], 11 | "member-ordering": [ 12 | true, 13 | "static-before-instance", 14 | "variables-before-functions" 15 | ], 16 | "no-arg": true, 17 | "no-bitwise": false, 18 | "no-console": [ 19 | true, 20 | "debug", 21 | "info", 22 | "time", 23 | "timeEnd", 24 | "trace" 25 | ], 26 | "no-construct": true, 27 | "no-debugger": true, 28 | "no-duplicate-variable": true, 29 | "no-empty": true, 30 | "no-eval": true, 31 | "no-inferrable-types": true, 32 | "no-shadowed-variable": true, 33 | "no-string-literal": true, 34 | "no-switch-case-fall-through": true, 35 | "no-trailing-whitespace": false, 36 | "no-unused-expression": true, 37 | "no-use-before-declare": true, 38 | "no-var-keyword": true, 39 | "object-literal-sort-keys": false, 40 | "one-line": [ false ], 41 | "quotemark": [ true, "double" ], 42 | "radix": true, 43 | "semicolon": true, 44 | "triple-equals": [ true ], 45 | "variable-name": false, 46 | "whitespace": [ 47 | true, 48 | "check-branch", 49 | "check-decl", 50 | "check-operator", 51 | "check-separator", 52 | "check-type" 53 | ] 54 | } 55 | } -------------------------------------------------------------------------------- /typings/InAppBillingHelper.android.d.ts: -------------------------------------------------------------------------------- 1 | type ProductType = "inapp" | "subs"; 2 | 3 | declare namespace com { 4 | export var google: any; 5 | 6 | export namespace tangrainc { 7 | export namespace inappbilling { 8 | export class InAppBillingHelper { 9 | public static BUY_INTENT_REQUEST_CODE: number; 10 | 11 | constructor(context: android.content.Context, productIdentifiers: Array); 12 | public getProducts(type: ProductType): any; /* ListenableFuture */ 13 | public startBuyIntent(foregroundActivity: android.app.Activity, productIdentifier: string, type: ProductType, payload: string); 14 | public consumePurchase(token: string): any /* ListenableFuture */ 15 | public getPurchases(continuationToken: string, type: ProductType): any ; 16 | } 17 | } 18 | } 19 | } --------------------------------------------------------------------------------