forked from danielsogl/awesome-cordova-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
910 lines (796 loc) · 26.5 KB
/
index.ts
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
import { Cordova, CordovaProperty, IonicNativePlugin, Plugin } from '@ionic-native/core';
import { Injectable } from '@angular/core';
export interface IAPProductOptions {
id: string;
alias?: string;
type: string;
}
export interface IRefeshResult {
cancelled(fn: () => void): void;
failed(fn: () => void): void;
completed(fn: () => void): void;
finished(fn: () => void): void;
}
export type IAPProducts = IAPProduct[] & {
/**
* Get product by ID
*/
byId: { [id: string]: IAPProduct };
/**
* Get product by alias
*/
byAlias: { [alias: string]: IAPProduct };
/**
* Remove all products (for testing only).
*/
reset: () => {};
};
export type IAPQueryCallback = ((product: IAPProduct) => void) | ((error: IAPError) => void);
export interface IAPProduct {
id: string;
alias?: string;
type: string;
state: string;
title: string;
description: string;
priceMicros: number;
price: string;
currency: string;
loaded: boolean;
valid: boolean;
canPurchase: boolean;
owned: boolean;
downloading?: boolean;
downloaded?: boolean;
lastRenewalDate?: Date;
expiryDate?: Date;
introPrice?: string;
introPriceMicros?: number;
introPriceNumberOfPeriods?: number;
introPriceSubscriptionPeriod?: string;
introPricePaymentMode?: string;
ineligibleForIntroPrice?: boolean;
billingPeriod?: number;
billingPeriodUnit?: string;
trialPeriod?: number;
trialPeriodUnit?: string;
additionalData?: any;
transaction?: PlayStoreReceipt | AppStoreReceipt;
/**
* Call `product.finish()` to confirm to the store that an approved order has been delivered.
*
* This will change the product state from `APPROVED` to `FINISHED` (see product life-cycle).
*
* As long as you keep the product in state `APPROVED`:
*
* - the money may not be in your account (i.e. user isn't charged)
* - you will receive the `approved` event each time the application starts,
* where you should try again to finish the pending transaction.
*
* **example use**
*
* ```js
* store.when("product.id").approved(function(product){
* // synchronous
* app.unlockFeature();
* product.finish();
* });
* ```
*
* ```js
* store.when("product.id").approved(function(product){
* // asynchronous
* app.downloadFeature(function() {
* product.finish();
* });
* });
* ```
*/
finish(): void;
/**
* Initiate purchase validation as defined by the `store.validator` attribute.
*
* **return value**
*
* A Promise with the following methods:
*
* - `done(function(product){})`
* - called whether verification failed or succeeded.
* - `expired(function(product){})`
* - called if the purchase expired.
* - `success(function(product, purchaseData){})`
* - called if the purchase is valid and verified.
* - `purchaseData` is the device dependent transaction details
* returned by the validator, which you can most probably ignore.
* - `error(function(err){})`
* - validation failed, either because of expiry or communication
* failure.
* - `err` is a store.Error object, with a code expected to be
* `store.ERR_PAYMENT_EXPIRED` or `store.ERR_VERIFICATION_FAILED`.
*/
verify(): any;
set(key: string, value: any): void;
stateChanged(): void;
on(event: string, callback: Function): void;
once(event: string, callback: Function): void;
off(callback: Function): void;
trigger(action: string, args: any): void;
}
export interface IAPProductEvents {
/** Called when product data is loaded from the store. */
loaded: (callback: IAPQueryCallback) => IAPProductEvents;
/** Called when any change occured to a product. */
updated: (callback: IAPQueryCallback) => IAPProductEvents;
/** Called when an order failed. The `err` parameter is an IAPError object. */
error: (callback: IAPQueryCallback) => IAPProductEvents;
/** Called when a product order is approved. */
approved: (callback: IAPQueryCallback) => IAPProductEvents;
/** Called when a non-consumable product or subscription is owned. */
owned: (callback: IAPQueryCallback) => IAPProductEvents;
/** Called when a product order is cancelled by the user. */
cancelled: (callback: IAPQueryCallback) => IAPProductEvents;
/** Called when an order is refunded by the user. */
refunded: (callback: IAPQueryCallback) => IAPProductEvents;
/** Called when product has just been registered. */
registered: (callback: IAPQueryCallback) => IAPProductEvents;
/** Called when the product details have been successfully loaded. */
valid: (callback: IAPQueryCallback) => IAPProductEvents;
/** Called when the product cannot be loaded from the store. */
invalid: (callback: IAPQueryCallback) => IAPProductEvents;
/** Called when an order has just been requested. */
requested: (callback: IAPQueryCallback) => IAPProductEvents;
/** Called when the purchase process has been initiated. */
initiated: (callback: IAPQueryCallback) => IAPProductEvents;
/** Called when the purchase process has completed. */
finished: (callback: IAPQueryCallback) => IAPProductEvents;
/** Called when receipt validation successful. */
verified: (callback: IAPQueryCallback) => IAPProductEvents;
/** Called when receipt verification failed. */
unverified: (callback: IAPQueryCallback) => IAPProductEvents;
/** Called when validation find a subscription to be expired. */
expired: (callback: IAPQueryCallback) => IAPProductEvents;
/** Called when content download is started. */
downloading: (product: IAPProduct, progress: any, time_remaining: any) => IAPProductEvents;
/** Called when content download has successfully completed. */
downloaded: (callback: IAPQueryCallback) => IAPProductEvents;
}
export type PlayStoreReceipt = {
id: string;
purchaseState: number;
purchaseToken: string;
receipt: string;
signature: string;
type: 'android-playstore';
};
export type AppStoreReceipt = {
id: string;
appStoreReceipt: string;
original_transaction_id: string;
type: 'ios-appstore';
};
/**
* @hidden
*/
export class IAPError {
code: number;
message: string;
}
/**
* @name In App Purchase 2
* @description
* In-App Purchase on iOS, Android, Windows, macOS and XBox.
*
* ## Features
*
* | | ios | android | win-8 | win-10/uwp | mac |
* |--|--|--|--|--|--|
* | consumables | ✅ | ✅ | ✅ | ✅ | ✅ |
* | non consumables | ✅ | ✅ | ✅ | ✅ | ✅ |
* | subscriptions | ✅ | ✅ | ✅ | ✅ | ✅ |
* | restore purchases | ✅ | ✅ | ✅ | ✅ | ✅ |
* | receipt validations | ✅ | ✅ | | ✅ | ✅ |
* | downloadable content | ✅ | | | | ✅ |
* | introductory prices | ✅ | ✅ | | ✅ | ✅ |
*
* Supports:
*
* - **iOS** version 7.0 or higher.
* - **Android** version 2.2 (API level 8) or higher
* - with Google Play client version 3.9.16 or higher
* - **Windows** Store/Phone 8.1 or higher
* - **Windows 10 Mobile**
* - **macOS** version 10
* - **Xbox One**
* - (and any platform supporting Microsoft's UWP)
*
* @usage
* ```typescript
* import { InAppPurchase2 } from '@ionic-native/in-app-purchase-2/ngx';
*
* constructor(public platform: Platform, private store: InAppPurchase2) {
* platform.ready().then(() => {
* this.store.register({
* id: "my_product_id",
* type: this.store.NON_RENEWING_SUBSCRIPTION,
* });
* this.store.when("my_product_id")
* .approved(p => p.verify())
* .verified(p => p.finish());
* this.store.refresh();
* });
* }
*
* ...
*
* this.store.order("my_product_id");
*
* ```
*
* ## Full example
*
* ```typescript
* // After platform ready
* this.store.verbosity = this.store.DEBUG;
* this.store.register({
* id: "my_product_id",
* type: this.store.PAID_SUBSCRIPTION,
* });
*
* // Register event handlers for the specific product
* this.store.when("my_product_id").registered( (product: IAPProduct) => {
* console.log('Registered: ' + JSON.stringify(product));
* });
*
* // Updated
* this.store.when("my_product_id").updated( (product: IAPProduct) => {
* console.log('Updated' + JSON.stringify(product));
* });
*
* // User closed the native purchase dialog
* this.store.when("my_product_id").cancelled( (product) => {
* console.error('Purchase was Cancelled');
* });
*
* // Track all store errors
* this.store.error( (err) => {
* console.error('Store Error ' + JSON.stringify(err));
* });
*
* // Run some code only when the store is ready to be used
* this.store.ready(() => {
* console.log('Store is ready');
* console.log('Products: ' + JSON.stringify(this.store.products));
* console.log(JSON.stringify(this.store.get("my_product_id")));
* });
*
* // Refresh the status of in-app products
* this.store.refresh();
*
* ...
*
* // To make a purchase
* this.store.order("my_product_id");
*
* ```
*
* ## Philosophy
*
* The API is mostly events based. As a user of this plugin,
* you will have to register listeners to changes happening to the products
* you register.
*
* The core of the listening mechanism is the `when()` method. It allows you to
* be notified of changes to one or a set of products using a query mechanism:
* ```typescript
* this.store.when("product").updated(refreshScreen); // match any product
* this.store.when("full_version").owned(unlockApp); // match a specific product
* this.store.when("subscription").approved(serverCheck); // match all subscriptions
* this.store.when("downloadable content").downloaded(showContent);
* ```
*
* The `updated` event is fired whenever one of the fields of a product is
* changed (its `owned` status for instance).
*
* This event provides a generic way to track the statuses of your purchases,
* to unlock features when needed and to refresh your views accordingly.
*
* ## Registering products
*
* The store needs to know the type and identifiers of your products before you
* can use them in your code.
*
* Use `store.register()` to define them before your first call to `store.refresh()`.
*
* Once registered, you can use `store.get()` to retrieve an `IAPProduct` object.
*
* ```typescript
* this.store.register({
* id: "my_consumable1",
* type: this.store.CONSUMABLE
* });
* ...
* const p = this.store.get("my_consumable1");
* ```
*
* The product `id` and `type` have to match products defined in your
* Apple, Google or Microsoft developer consoles.
*
* Learn more about it [from the wiki](https://github.com/j3k0/cordova-plugin-purchase/wiki).
*
* ## Displaying products
*
* Right after you registered your products, nothing much is known about them
* except their `id`, `type` and an optional `alias`.
*
* When you perform the initial call to `store.refresh()`, the platforms' server will
* be contacted to load informations about the registered products: human
* readable `title` and `description`, `price`, etc.
*
* This isn't an optional step, store owners require you
* to display information about a product exactly as retrieved from their server: no
* hard-coding of price and title allowed! This is also convenient for you
* as you can change the price of your items knowing that it'll be reflected instantly
* on your clients' devices.
*
* Note that the information may not be available when the first view that needs
* them appears on screen. For you, the best option is to have your view monitor
* changes made to the product.
*
* ## Purchasing
*
* #### initiate a purchase
*
* Purchases are initiated using the `store.order("some_product_id")` method.
*
* The store will manage the internal purchase flow. It'll end:
*
* - with an `approved` event. The product enters the `APPROVED` state.
* - with a `cancelled` event. The product gets back to the `VALID` state.
* - with an `error` event. The product gets back to the `VALID` state.
*
* See the product life-cycle section for details about product states.
*
* #### finish a purchase
*
* Once the transaction is approved, the product still isn't owned: the store needs
* confirmation that the purchase was delivered before closing the transaction.
*
* To confirm delivery, you'll use the `product.finish()` method.
*
* #### example usage
*
* During initialization:
* ```typescript
* this.store.when("extra_chapter").approved((product: IAPProduct) => {
* // download the feature
* app.downloadExtraChapter()
* .then(() => product.finish());
* });
* ```
*
* When the purchase button is clicked:
* ```typescript
* this.store.order("extra_chapter");
* ```
*
* #### un-finished purchases
*
* If your app wasn't able to deliver the content, `product.finish()` won't be called.
*
* Don't worry: the `approved` event will be re-triggered the next time you
* call `store.refresh()`, which can very well be the next time
* the application starts. Pending transactions are persistant.
*
* #### simple case
*
* In the most simple case, where:
*
* - delivery of purchases is only local ;
* - you don't want (or need) to implement receipt validation ;
*
* You may just want to finish all purchases automatically. You can do it this way:
* ```js
* this.store.when("product").approved((p: IAPProduct) => p.finish());
* ```
*
* NOTE: the "product" query will match any purchases (see "queries" to learn more details about queries).
*
* ## Receipt validation
*
* To get the most up-to-date information about purchases (in case a purchase have been canceled, or a subscription renewed),
* you should implement server side receipt validation.
*
* This also protects you against fake "purchases", made by some users using
* "free in-app purchase" apps on their devices.
*
* When a purchase has been approved by the store, it's enriched with
* transaction information (see `product.transaction` attribute).
*
* To verify a purchase you'll have to do three things:
*
* - configure the validator.
* - call `product.verify()` from the `approved` event, before finishing the transaction.
* - finish the transaction when transaction is `verified`.
*
* **Shameless Plug**: this is a feature many users struggle with, so as the author of this plugin, we can provide it to you as-a-service: https://billing.fovea.cc/
* (which is free until you start making serious money)
*
* #### example using a validation URL
*
* ```js
* this.store.validator = "https://billing.fovea.cc/";
*
* this.store.when("my stuff")
* .approved((p: IAPProduct) => p.verify())
* .verified((p: IAPProduct) => p.finish());
* ```
*
* ## Subscriptions
*
* For subscription, you MUST implement remote receipt validation.
*
* When the receipt validator returns a `store.PURCHASE_EXPIRED` error code, the subscription will
* automatically loose its `owned` status.
*
* Typically, you'll enable and disable access to your content this way.
* ```typescript
* this.store.when("my_subcription").updated((product: IAPProduct) => {
* if (product.owned)
* app.subscriberMode();
* else
* app.guestMode();
* });
* ```
*
* ## Product life-cycle
*
* A product will change state during the application execution.
*
* Find below a diagram of the different states a product can pass by.
*
* ```
* REGISTERED +--> INVALID
* |
* +--> VALID +--> REQUESTED +--> INITIATED +-+
* |
* ^ +------------------------------+
* | |
* | | +--> DOWNLOADING +--> DOWNLOADED +
* | | | |
* | +--> APPROVED +--------------------------------+--> FINISHED +--> OWNED
* | |
* +-------------------------------------------------------------+
*
* #### Notes
*
* - When finished, a consumable product will get back to the `VALID` state, while other will enter the `OWNED` state.
* - Any error in the purchase process will bring a product back to the `VALID` state.
* - During application startup, products may go instantly from `REGISTERED` to `APPROVED` or `OWNED`, for example if they are purchased non-consumables or non-expired subscriptions.
* - Non-Renewing Subscriptions are iOS products only. Please see the [iOS Non Renewing Subscriptions documentation](https://github.com/j3k0/cordova-plugin-purchase/blob/master/doc/ios.md#non-renewing) for a detailed explanation.
*
* ## events
*
* - `loaded(IAPProduct)`
* - Called when product data is loaded from the store.
* - `updated(IAPProduct)`
* - Called when any change occured to a product.
* - `error(err)`
* - Called when an order failed.
* - The `err` parameter is an error object
* - `approved(IAPProduct)`
* - Called when a product order is approved.
* - `owned(IAPProduct)`
* - Called when a non-consumable product or subscription is owned.
* - `cancelled(IAPProduct)`
* - Called when a product order is cancelled by the user.
* - `refunded(IAPProduct)`
* - Called when an order is refunded by the user.
* - Actually, all other product states have their promise
* - `registered`, `valid`, `invalid`, `requested`,
* `initiated` and `finished`
* - `verified(IAPProduct)`
* - Called when receipt validation successful
* - `unverified(IAPProduct)`
* - Called when receipt verification failed
* - `expired(IAPProduct)`
* - Called when validation find a subscription to be expired
* - `downloading(IAPProduct, progress, time_remaining)`
* - Called when content download is started
* - `downloaded(IAPProduct)`
* - Called when content download has successfully completed
*
* ## Learn More
*
* - [GitHub](https://github.com/j3k0/cordova-plugin-purchase)
* - [GitBook](https://purchase.cordova.fovea.cc/)
* - [Wiki](https://github.com/j3k0/cordova-plugin-purchase/wiki)
* - [API reference](https://github.com/j3k0/cordova-plugin-purchase/blob/master/doc/api.md)
*
* ## Technical Support or Questions
*
* If you have questions or need help integrating In-App Purchase, [Open an Issue on GitHub](https://github.com/j3k0/cordova-plugin-purchase/issues) or email us at _support@fovea.cc_.
*
* @interfaces
* IAPProduct
* IAPProductOptions
* IAPProductEvents
* ```
*/
@Plugin({
pluginName: 'InAppPurchase2',
plugin: 'cordova-plugin-purchase',
pluginRef: 'store',
repo: 'https://github.com/j3k0/cordova-plugin-purchase',
platforms: ['iOS', 'Android', 'Windows'],
install: 'ionic cordova plugin add cordova-plugin-purchase --variable BILLING_KEY="<ANDROID_BILLING_KEY>"',
})
@Injectable()
export class InAppPurchase2 extends IonicNativePlugin {
@CordovaProperty()
QUIET: number;
@CordovaProperty()
ERROR: number;
@CordovaProperty()
WARNING: number;
@CordovaProperty()
INFO: number;
@CordovaProperty()
DEBUG: number;
/**
* Debug level. Use QUIET, ERROR, WARNING, INFO or DEBUG constants
*/
@CordovaProperty()
verbosity: number;
/**
* Set to true to clear the transaction queue. Not recommended for production.
* https://github.com/j3k0/cordova-plugin-purchase/blob/master/doc/api.md#random-tips
*/
@CordovaProperty()
autoFinishTransactions: boolean;
/**
* Set to true to invoke the platform purchase sandbox. (Windows only)
*/
@CordovaProperty()
sandbox: boolean;
/**
* Set to true to disable downloading of hosted content. (Apple only).
* Useful in development or when migrating your app away from Apple Hosted Content.
*/
@CordovaProperty()
disableHostedContent: boolean;
@CordovaProperty()
FREE_SUBSCRIPTION: string;
@CordovaProperty()
PAID_SUBSCRIPTION: string;
@CordovaProperty()
NON_RENEWING_SUBSCRIPTION: string;
@CordovaProperty()
CONSUMABLE: string;
@CordovaProperty()
NON_CONSUMABLE: string;
@CordovaProperty()
ERR_SETUP: number;
@CordovaProperty()
ERR_LOAD: number;
@CordovaProperty()
ERR_PURCHASE: number;
@CordovaProperty()
ERR_LOAD_RECEIPTS: number;
@CordovaProperty()
ERR_CLIENT_INVALID: number;
@CordovaProperty()
ERR_PAYMENT_CANCELLED: number;
@CordovaProperty()
ERR_PAYMENT_INVALID: number;
@CordovaProperty()
ERR_PAYMENT_NOT_ALLOWED: number;
@CordovaProperty()
ERR_UNKNOWN: number;
@CordovaProperty()
ERR_REFRESH_RECEIPTS: number;
@CordovaProperty()
ERR_INVALID_PRODUCT_ID: number;
@CordovaProperty()
ERR_FINISH: number;
@CordovaProperty()
ERR_COMMUNICATION: number;
@CordovaProperty()
ERR_SUBSCRIPTIONS_NOT_AVAILABLE: number;
@CordovaProperty()
ERR_MISSING_TOKEN: number;
@CordovaProperty()
ERR_VERIFICATION_FAILED: number;
@CordovaProperty()
ERR_BAD_RESPONSE: number;
@CordovaProperty()
ERR_REFRESH: number;
@CordovaProperty()
ERR_PAYMENT_EXPIRED: number;
@CordovaProperty()
ERR_DOWNLOAD: number;
@CordovaProperty()
ERR_SUBSCRIPTION_UPDATE_NOT_AVAILABLE: number;
@CordovaProperty()
REGISTERED: string;
@CordovaProperty()
INVALID: string;
@CordovaProperty()
VALID: string;
@CordovaProperty()
REQUESTED: string;
@CordovaProperty()
INITIATED: string;
@CordovaProperty()
APPROVED: string;
@CordovaProperty()
FINISHED: string;
@CordovaProperty()
OWNED: string;
@CordovaProperty()
DOWNLOADING: string;
@CordovaProperty()
DOWNLOADED: string;
/* validation error codes */
@CordovaProperty()
INVALID_PAYLOAD: number;
@CordovaProperty()
CONNECTION_FAILED: number;
@CordovaProperty()
PURCHASE_EXPIRED: number;
@CordovaProperty()
PURCHASE_CONSUMED: number;
@CordovaProperty()
INTERNAL_ERROR: number;
@CordovaProperty()
NEED_MORE_DATA: number;
@CordovaProperty()
products: IAPProducts;
@CordovaProperty()
validator: string | ((url: string | IAPProduct, callback: Function) => void);
@CordovaProperty()
applicationUsername: string | (() => string);
@Cordova({ sync: true })
getApplicationUsername(): string {
return;
}
@CordovaProperty()
log: {
error: (message: string) => void;
warn: (message: string) => void;
info: (message: string) => void;
debug: (message: string) => void;
};
/**
* Get product by id or alias
* @param idOrAlias
*/
@Cordova({ sync: true })
get(idOrAlias: string): IAPProduct {
return;
}
/**
* Register error handler
* @param onError {Function} function to call on error
*/
@Cordova({ sync: true })
error(onError: Function): void {}
/**
* Add or register a product
* @param product {IAPProductOptions}
*/
@Cordova({ sync: true })
register(product: IAPProductOptions | IAPProductOptions[]): void {}
/**
*
* @param query
* @param event
* @param callback
* @return {IAPProductEvents}
*/
@Cordova({ sync: true })
when(query: string | IAPProduct, event?: string, callback?: IAPQueryCallback): IAPProductEvents {
return;
}
/**
* Identical to `when`, but the callback will be called only once. After being called, the callback will be unregistered.
* @param query {string | IAPProduct}
* @param [event] {event}
* @param [callback] {IAPQueryCallback}
* @return {IAPProductEvents}
*/
@Cordova({ sync: true })
once(query: string | IAPProduct, event?: string, callback?: IAPQueryCallback): IAPProductEvents {
return;
}
/**
* Unregister a callback. Works for callbacks registered with ready, when, once and error.
* @param callback {Function}
*/
@Cordova({ sync: true })
off(callback: Function): void {}
/**
* Initiate the purchase of a product.
*
* The `product` argument can be either:
*
* - the `IAPProduct` object
* - the product `id`
* - the product `alias`
*
* The `additionalData` argument is an optional object with attributes:
* - `oldPurchasedSkus`: a string array with the old subscription to upgrade/downgrade on Android. See: [android developer](https://developer.android.com/google/play/billing/billing_reference.html#upgrade-getBuyIntentToReplaceSkus) for more info
* - `developerPayload`: string representing the developer payload as described in [billing best practices](https://developer.android.com/google/play/billing/billing_best_practices.html)
* - `applicationUsername`: the identifier of the user in your application.
*
* See the "Purchasing section" to learn more about the purchase process.
*
* **return value**
*
* `store.order()` returns a Promise with the following methods:
*
* - `then` - called when the order was successfully initiated.
* - `error` - called if the order couldn't be initiated.
*/
@Cordova({ sync: true })
order(product: string | IAPProduct, additionalData?: any): { then: Function; error: Function } {
return;
}
@Cordova()
ready(callback: Function): void {
return;
}
/**
* After you're done registering your store's product and events handlers,
* time to call `store.refresh()`.
*
* This will initiate all the complex behind-the-scene work, to load product
* data from the servers and restore whatever already have been
* purchased by the user.
*
* Note that you can call this method again later during the application
* execution to re-trigger all that hard-work. It's kind of expensive in term of
* processing, so you'd better consider it twice.
*
* One good way of doing it is to add a "Refresh Purchases" button in your
* applications settings. This way, if delivery of a purchase failed or
* if a user wants to restore purchases he made from another device, he'll
* have a way to do just that.
*
* **example usage**
*
* ```typescript
* // ...
* // register products and events handlers here
* // ...
* //
* // then and only then, call refresh.
* this.store.refresh();
* ```
*
* **restore purchases**
*
* Add a "Refresh Purchases" button to call the `store.refresh()` method, like:
*
* `<button onclick="<pseudo_code>this.store.refresh()</pseudo_code>">Restore Purchases</button>`
*
* To make the restore purchases work as expected, please make sure that
* the "approved" event listener had be registered properly,
* and in the callback `product.finish()` should be called.
*/
@Cordova({ sync: true })
refresh(): IRefeshResult {
return;
}
/** Lightweight method like refresh but do not relogin user */
@Cordova({ sync: true })
update(): void {}
/** Opens the Manage Subscription page (AppStore, Play, Microsoft, ...). */
@Cordova({ sync: true })
manageSubscriptions(): void {}
/** Opens the Code Redemption Sheet on iOS. (AppStore). */
@Cordova({ sync: true })
redeem(): void {}
/** Opens the Manage Billing page (AppStore, Play, Microsoft, ...), where the user can update his/her payment methods. */
@Cordova({ sync: true })
manageBilling(): void {}
}