0.0.9 β€’ Published 9 months ago

emi-indo-cordova-plugin-iap v0.0.9

Weekly downloads
-
License
ISC
Repository
github
Last release
9 months ago

emi-indo-cordova-plugin-iap

Cordova Plugin cordova plugin In App Purchase

Support ( Consumable | Non-consumable | Subscriptions/installments )

Includes server side validation https://console.cloud.google.com

SDK (billing_version = 7.1.1) Release Notes:

Note

  • It's Not a fork, it's purely rewritten, clean of 3rd party code.

πŸ’°Sponsor this project

PayPal

Features

As per original sample:

  • SDK Initialize a BillingClient
  • Show products available to buy
  • Launch the purchase flow
  • Processing purchases
  • Fetching purchases
  • Fetching purchase history

Features NEW Method

  • getSubscriptionStatus (Free 200,000 requests per day)
  • redirectToSubscriptionCenter
  • redirectToSpecificSubscription
  • changeSubscription

Plugin Installation

cordova plugin add emi-indo-cordova-plugin-iap

Or

cordova plugin add https://github.com/EMI-INDO/emi-indo-cordova-plugin-iap

Remove

cordova plugin rm emi-indo-cordova-plugin-iap

Tabel Response Code = number

CodeDescription
0OK
1USER_CANCELED
2SERVICE_UNAVAILABLE
3BILLING_UNAVAILABLE
4ITEM_UNAVAILABLE
5DEVELOPER_ERROR
6ERROR
7ITEM_ALREADY_OWNED
8ITEM_NOT_OWNED
-1SERVICE_DISCONNECTED
-2FEATURE_NOT_SUPPORTED
12NETWORK_ERROR

Initialize

cordova.plugins.emiInAppPurchase.initialize((status) => {

                 console.log("User's Play Country: " + status) 

                },
                (error) => { console.error(JSON.stringify(error)) }

)

purchase Products

    cordova.plugins.emiInAppPurchase.purchaseProducts({
    
    productType: "Non-consumable", // string (Non-consumable | Consumable | Subscriptions)
    productId: "testId"
    },
    (result) => {

    const dataIsSuccess = result.isPurchasesSuccess; // boolean
    const dataProductType = result.productType; // Non-consumable | Consumable | Subscriptions
    const dataProductId = result.productsId; 
    const dataIsInstallment = result.isInstallmentPlansSupported; // boolean 

    if (dataIsSuccess && dataProductId === "testId"){

      if (dataProductType === 'Non-consumable'){

        console.log(JSON.stringify(result))

      } else if (dataProductType === 'Consumable'){

        console.log(JSON.stringify(result))

      } else if (dataProductType === 'Subscriptions'){

       if (dataIsInstallment){

         console.log(result.commitmentPaymentsCount)
         console.log(result.subsequentCommitmentPaymentsCount)

       }

       console.log(JSON.stringify(result))

    } 

    }


    },
    (error) => { // alert(error) 
   
   
   })

getSubscriptionStatus()

  • Create GCP service-account-key.json https://www.youtube.com/watch?v=gjAVd784WqE
  • after the service-account.json file is downlaod,
  • change the file name to service-account-key,
  • place the service-account-key.json file in the www folder.
Example of Cordova project structure

my-cordova-project/
β”œβ”€β”€ config.xml      
└── www/
    β”œβ”€β”€ css/            
    β”œβ”€β”€ js/         
    β”œβ”€β”€ img/        
    β”œβ”€β”€ service-account-key.json/   # File service-account  
    └── index.html  

Note

// NOTE: Essentially if all the settings are correct, you should wait 24 hours to test. getSubscriptionStatus // Free 200,000 requests per day cordova.plugins.emiInAppPurchase.getSubscriptionStatus({

    applicationName: "App Name",
    packageName: "com.xxxxxxx",
    purchaseToken: "token-xxxxxxx",
    subscriptionId: "id-xxxx" // productId

  },(data) => {

          
          console.log(JSON.stringify(data))

          const dataStatus = data.status; // RENEWED | CANCELED | ON_HOLD | EXPIRED | UNKNOWN
          const dataDetails = data.details;

          console.log(dataStatus)

          console.log(dataDetails.autoRenewing)
          console.log(dataDetails.countryCode)
          console.log(dataDetails.expiryTimeMillis)
          console.log(dataDetails.orderId)
          console.log(dataDetails.priceAmountMicros)
          console.log(dataDetails.priceCurrencyCode)
          console.log(dataDetails.startTimeMillis)


        },
        (error) => {

         console.error(JSON.stringify(error))

        });
## redirectToSubscriptionCenter()
- Use deep links to allow users to manage a subscription
```bash
cordova.plugins.emiInAppPurchase.redirectToSubscriptionCenter();

redirectToSpecificSubscription()

  • Link to a specific subscription management page (recommended)
cordova.plugins.emiInAppPurchase.redirectToSpecificSubscription();

changeSubscription()

  • Allow users to upgrade, downgrade, or change their subscription
  • replacementMode string value: CHARGE_PRORATED_PRICE | CHARGE_FULL_PRICE | WITHOUT_PRORATION | DEFERRED
// https://developer.android.com/google/play/billing/subscriptions#allow-users-change


cordova.plugins.emiInAppPurchase.changeSubscription({

        oldPurchaseToken: "",
        newProductId: "",
        selectedOfferIndex: 0,
        replacementMode: "" 

      },(status) => {

              console.log(JSON.stringify(status))

            },
            (error) => {

             console.error(JSON.stringify(error))

            });

Get Product Detail

Note

  • position = String
  • value = ProductId | Title | Description | Item_Price | Any
cordova.plugins.emiInAppPurchase.getProductDetail({

    productType: "Non-consumable", // string  (Non-consumable | Consumable | Subscriptions)
    productId: "id",
    position: "ProductId"
},
    (result) => { alert(result) },
    (error) => { alert(error) }
    
    )

Get Purchase History

Note

  • position = String
  • value = Purchase_Token | Original_Json | Quantity | Signature | Developer_Payload | Products | Purchase_Time | Any
cordova.plugins.emiInAppPurchase.getPurchaseHistory({

    productType: "Non-consumable", // string (Non-consumable | Consumable | Subscriptions)
    position: "Purchase_Token", 
    }, 
    (result) => { alert(result) },
    (error) => { alert(error) }

    )

Restore Purchases

Note

  • position = String
  • value = OrderId | Purchase_Token | Package_Name | Purchase_Time | Purchase_State | Quantity | Signature | Original_Json | ProductId | Any
cordova.plugins.emiInAppPurchase.restorePurchases({

    productType: "Non-consumable", // string  (Non-consumable | Consumable | Subscriptions)
    position: "OrderId", 
},
    (result) => { alert(result) },
    (error) => { alert(error) }
    
    )

Support Platform ( Android )

Coming soon Plugin ( Store user purchase data )

  • Firebase Authentication
  • Firebase Realtime Database

πŸ’°Sponsor this project

PayPal