<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Arpit </title>
    <description>The latest articles on DEV Community by Arpit  (@arpit_123).</description>
    <link>https://dev.to/arpit_123</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1146268%2Fcab87e92-7c41-4dad-b410-3e198245e28d.png</url>
      <title>DEV Community: Arpit </title>
      <link>https://dev.to/arpit_123</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/arpit_123"/>
    <language>en</language>
    <item>
      <title>Setup Cordova-plugin-purchase v13 in ionic</title>
      <dc:creator>Arpit </dc:creator>
      <pubDate>Fri, 25 Aug 2023 13:21:24 +0000</pubDate>
      <link>https://dev.to/arpit_123/setup-cordova-plugin-purchase-v13-in-ionic-52ec</link>
      <guid>https://dev.to/arpit_123/setup-cordova-plugin-purchase-v13-in-ionic-52ec</guid>
      <description>&lt;p&gt;To begin, install Cordova-plugin-purchase v13 by using:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm i cordova-plugin-purchase&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Import the library:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;import "cordova-plugin-purchase";&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then, access the class methods as follows:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const { store, ProductType, Platform } = CdvPurchase;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Alternatively, you can use:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;CdvPurchase.Store;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Next, set the verbosity level for console logging:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;store.verbosity = LogLevel.DEBUG; // Use LogLevel constants&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Here are the available verbosity levels:&lt;/p&gt;

&lt;p&gt;LogLevel.QUIET (0) to disable all logging (default)&lt;br&gt;
LogLevel.ERROR (1) to display only error messages&lt;br&gt;
LogLevel.WARNING (2) to show warnings and errors&lt;br&gt;
LogLevel.INFO (3) to show informational messages&lt;br&gt;
LogLevel.DEBUG (4) to enable internal debugging messages&lt;br&gt;
Initialize the validator value using:&lt;/p&gt;

&lt;p&gt;s&lt;code&gt;tore.validator = yourValidatorMethodOrApiRoute;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Register your products:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;store.register([&lt;br&gt;
{&lt;br&gt;
id: 'subscription1',&lt;br&gt;
type: ProductType.PAID_SUBSCRIPTION,&lt;br&gt;
platform: Platform.APPLE_APPSTORE,&lt;br&gt;
},&lt;br&gt;
{&lt;br&gt;
id: 'subscription2',&lt;br&gt;
type: ProductType.PAID_SUBSCRIPTION,&lt;br&gt;
platform: Platform.GOOGLE_PLAY,&lt;br&gt;
},&lt;br&gt;
{&lt;br&gt;
id: 'consumable1',&lt;br&gt;
type: ProductType.CONSUMABLE,&lt;br&gt;
platform: Platform.BRAINTREE,&lt;br&gt;
},&lt;br&gt;
]);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Set up an error callback function:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;store.error(console.warn);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;// OR&lt;/p&gt;

&lt;p&gt;&lt;code&gt;store.error(() =&amp;gt; {&lt;br&gt;
// Your error-handling code&lt;br&gt;
});&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Initialize the in-app purchase plugin:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;store.initialize(); // Pass platforms if needed&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Refresh product prices and purchase statuses:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;store.update();&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Replay user transactions (Apple AppStore requirement):&lt;/p&gt;

&lt;p&gt;&lt;code&gt;store.restorePurchases();&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To display the subscription popup, use:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;store.get("Your_subscription_id")?.getOffer()?.order();&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If &lt;code&gt;store.get("Your_subscription_id")&lt;/code&gt; is consistently undefined, use:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;store.ready(() =&amp;gt; {&lt;br&gt;
store.when().productUpdated((product) =&amp;gt; {&lt;br&gt;
setCanBuy(true);&lt;br&gt;
setStoreProductValue(store.get("Your_subscription_id"));&lt;br&gt;
});&lt;br&gt;
});&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Here, upon store readiness, the productUpdated event callback is triggered when product details are successfully fetched or updated. The product details are stored in a state, and the subscription model is triggered using &lt;/p&gt;

&lt;p&gt;&lt;code&gt;StoreProductValue.getOffer().order()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Once the user initiates a transaction, the validator runs. You can handle the events using:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;store.when().approved(async (transaction) =&amp;gt; {&lt;br&gt;
// Your code&lt;br&gt;
transaction.verify();&lt;br&gt;
}).verified((receipt) =&amp;gt; {&lt;br&gt;
if (Object.values(Subscription_Plans).includes(receipt?.id)) {&lt;br&gt;
receipt.finish();&lt;br&gt;
}&lt;br&gt;
// Your code&lt;br&gt;
});&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Feel free to adapt these instructions to ensure smooth operation within your app.tsx file. This setup will enable the subscription model to run effectively.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
