<?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: Hamza Hsain</title>
    <description>The latest articles on DEV Community by Hamza Hsain (@hsain_hamza).</description>
    <link>https://dev.to/hsain_hamza</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%2F200147%2F46509e8a-ba97-4715-8366-3ccdbb11dbd1.jpg</url>
      <title>DEV Community: Hamza Hsain</title>
      <link>https://dev.to/hsain_hamza</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hsain_hamza"/>
    <language>en</language>
    <item>
      <title>In App Purchase with Ionic / Cordova</title>
      <dc:creator>Hamza Hsain</dc:creator>
      <pubDate>Mon, 22 Jul 2019 15:43:16 +0000</pubDate>
      <link>https://dev.to/bewizyu/in-app-purchase-with-ionic-cordova-3fjc</link>
      <guid>https://dev.to/bewizyu/in-app-purchase-with-ionic-cordova-3fjc</guid>
      <description>&lt;p&gt;Article initialement posté sur &lt;a href="https://medium.com/bewizyu/in-app-purchase-with-ionic-cordova-18960239f989" rel="noopener noreferrer"&gt;Medium&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In App Purchase (or integrated purchase) gives the opportunity to sell additional content within a native mobile application (smartphone and tablet). If your product matches the in-app purchase categories bellow, then you can, and even must, use In app-purchase.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3044%2F1%2AA7DWo3FqQqnAuJiXNVQrGg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3044%2F1%2AA7DWo3FqQqnAuJiXNVQrGg.png" alt="A typical example of IAP"&gt;&lt;/a&gt;&lt;em&gt;A typical example of IAP&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What can I sell using IAP ?
&lt;/h2&gt;

&lt;p&gt;In principle, you can sell whatever you want as long as it belongs to the following categories :&lt;/p&gt;

&lt;h3&gt;
  
  
  Consumable
&lt;/h3&gt;

&lt;p&gt;Users can purchase different types of consumables, such as lives or gems in a game, to further their progress through an app. Consumable in-app purchases are used once, are depleted, and can be purchased again.&lt;/p&gt;

&lt;h3&gt;
  
  
  Non-Consumable
&lt;/h3&gt;

&lt;p&gt;Users can purchase non-consumable, premium features within an app. Non-consumables are purchased once and do not expire, such as additional filters in a photo app.&lt;/p&gt;

&lt;h3&gt;
  
  
  Auto-Renewable Subscriptions
&lt;/h3&gt;

&lt;p&gt;Users can purchase access to services or periodically updated content, such as monthly access to cloud storage or a weekly subscription to a magazine.&lt;/p&gt;

&lt;h3&gt;
  
  
  Non-Renewing Subscriptions
&lt;/h3&gt;

&lt;p&gt;Users can purchase access to services or content for a limited duration, such as a season pass to streaming content. This type of subscription does not renew automatically, so users need to renew each time.&lt;/p&gt;

&lt;p&gt;You can find more informations here =&amp;gt; &lt;a href="https://developer.apple.com/in-app-purchase/" rel="noopener noreferrer"&gt;the apple documentation&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Our Bewiz Spin App
&lt;/h2&gt;

&lt;p&gt;We want to create a mobile app in which the user can buy credits that we will call &lt;strong&gt;Bewiz.&lt;/strong&gt; With these Bewizs he can spin a wheel, to try to win gifts 🎁 (1 Bewiz =&amp;gt; 1 spin)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F9216%2F1%2AF8D_fSLWaMv0vszCw9Ytbg.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F9216%2F1%2AF8D_fSLWaMv0vszCw9Ytbg.jpeg" alt="Photo by [Navneet Shanu ](https://www.pexels.com/@navneet-shanu-202773?utm_content=attributionCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=pexels)from [Pexels](https://www.pexels.com/photo/brown-carriage-wheel-672630/?utm_content=attributionCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=pexels)"&gt;&lt;/a&gt;&lt;em&gt;Photo by &lt;a href="https://www.pexels.com/@navneet-shanu-202773?utm_content=attributionCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=pexels" rel="noopener noreferrer"&gt;Navneet Shanu &lt;/a&gt;from &lt;a href="https://www.pexels.com/photo/brown-carriage-wheel-672630/?utm_content=attributionCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=pexels" rel="noopener noreferrer"&gt;Pexels&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;For our case, we will need to use consumable products because it's used to buy credits that are used once to spin the wheel.&lt;/p&gt;

&lt;p&gt;Lets imagine that we have this set of suggested products :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2358%2F1%2AN2ah_00DHtC_Spp_yapd0Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2358%2F1%2AN2ah_00DHtC_Spp_yapd0Q.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;10&lt;/strong&gt; Bewiz for &lt;strong&gt;10€&lt;/strong&gt;, &lt;strong&gt;50&lt;/strong&gt; Bewiz for &lt;strong&gt;40€&lt;/strong&gt; and &lt;strong&gt;100&lt;/strong&gt; Bewiz for &lt;strong&gt;75€&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's see how can we put all this in place … 😀&lt;/p&gt;

&lt;h2&gt;
  
  
  What I need to set up IAP
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Ionic / Cordova mobile application
&lt;/h3&gt;

&lt;p&gt;As we will develop an ionic mobile app, you can follow these steps to initiate your project :&lt;br&gt;
&lt;a href="https://ionicframework.com/getting-started#cli" rel="noopener noreferrer"&gt;&lt;strong&gt;Free Mobile App Development: Getting Started with Ionic Apps&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;Create an Ionic App using one of our ready-made app templates, or a blank one to start fresh. Check out the Market for…&lt;/em&gt; ionicframework.com&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Server side application
&lt;/h3&gt;

&lt;p&gt;For security reasons, the purchase validation should be done in the server side.&lt;/p&gt;

&lt;p&gt;After each purchase the store returns a receipt data that should be validated in the server side (a base64 string for IOS, and a Json format for Android).&lt;/p&gt;

&lt;p&gt;For our Bewiz Spin we will use a PHP server side receipt validation using this open source library :&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/aporat" rel="noopener noreferrer"&gt;
        aporat
      &lt;/a&gt; / &lt;a href="https://github.com/aporat/store-receipt-validator" rel="noopener noreferrer"&gt;
        store-receipt-validator
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      PHP receipt validator for Apple iTunes, Google Play and Amazon App Store
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;store-receipt-validator&lt;/h1&gt;
&lt;/div&gt;
&lt;p&gt;&lt;a href="https://packagist.org/packages/aporat/store-receipt-validator" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/6db935b196336db3eec0f9ee2a8d7b0298cb762b6c133ba77690c234e411c2d8/68747470733a2f2f706f7365722e707567782e6f72672f61706f7261742f73746f72652d726563656970742d76616c696461746f722f76657273696f6e2e706e67" alt="Latest Stable Version"&gt;&lt;/a&gt;
&lt;a href="https://packagist.org/packages/aporat/store-receipt-validator" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/581ec107dff51ed15da1ede3a97e529c869bb4efa9849bfa1ae26737e6564f45/68747470733a2f2f706f7365722e707567782e6f72672f61706f7261742f73746f72652d726563656970742d76616c696461746f722f642f746f74616c2e706e67" alt="Composer Downloads"&gt;&lt;/a&gt;
&lt;a href="https://github.com/aporat/store-receipt-validator/actions" rel="noopener noreferrer"&gt;&lt;img src="https://github.com/aporat/store-receipt-validator/workflows/Tests/badge.svg" alt="Build Status"&gt;&lt;/a&gt;
&lt;a href="https://scrutinizer-ci.com/g/aporat/store-receipt-validator/?branch=master" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/ccec1f3c432b04da3344a2a952a386c9ad680ae604c5ebfefabb6fea00817d22/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f61706f7261742f73746f72652d726563656970742d76616c696461746f722f6261646765732f636f7665726167652e706e673f623d6d6173746572" alt="Code Coverage"&gt;&lt;/a&gt;
&lt;a href="https://scrutinizer-ci.com/g/aporat/store-receipt-validator/?branch=master" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/6eb1512a78530c5f4312fa6f4e212ebf2a0b27a3cf29d35a28ececdcd9801e2f/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f61706f7261742f73746f72652d726563656970742d76616c696461746f722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572" alt="Scrutinizer Code Quality"&gt;&lt;/a&gt;
&lt;a href="https://github.styleci.io/repos/14928361" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/8824d10fde368e41430b5d8393856a25821f084c4df0e8168fc4afa9c11d684b/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f31343932383336312f736869656c643f6272616e63683d6d6173746572" alt="StyleCI"&gt;&lt;/a&gt;
&lt;a href="https://packagist.org/packages/aporat/store-receipt-validator" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/eb33db76a23777c408916510f76a9225f594469b532bba45ed6ef0c5b7109ce2/68747470733a2f2f706f7365722e707567782e6f72672f61706f7261742f73746f72652d726563656970742d76616c696461746f722f6c6963656e73652e737667" alt="License"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;PHP receipt validator for Apple iTunes, Google Play and Amazon App Store&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Requirements&lt;/h2&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;PHP &amp;gt;= 7.3&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Installation&lt;/h2&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;composer require aporat/store-receipt-validator&lt;/code&gt;&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Quick Example&lt;/h2&gt;

&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h3 class="heading-element"&gt;iTunes&lt;/h3&gt;

&lt;/div&gt;
&lt;div class="highlight highlight-text-html-php notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;&lt;span class="pl-k"&gt;use&lt;/span&gt; &lt;span class="pl-v"&gt;ReceiptValidator&lt;/span&gt;\iTunes\&lt;span class="pl-v"&gt;Validator&lt;/span&gt; &lt;span class="pl-k"&gt;as&lt;/span&gt; iTunesValidator
&lt;span class="pl-s1"&gt;&lt;span class="pl-c1"&gt;$&lt;/span&gt;validator&lt;/span&gt; = &lt;span class="pl-k"&gt;new&lt;/span&gt; iTunesValidator(iTunesValidator::&lt;span class="pl-c1"&gt;ENDPOINT_PRODUCTION&lt;/span&gt;); &lt;span class="pl-c"&gt;// Or iTunesValidator::ENDPOINT_SANDBOX if sandbox testing&lt;/span&gt;

&lt;span class="pl-s1"&gt;&lt;span class="pl-c1"&gt;$&lt;/span&gt;receiptBase64Data&lt;/span&gt; = &lt;span class="pl-s"&gt;'&lt;span class="pl-s"&gt;ewoJInNpZ25hdHVyZSIgPSAiQXBNVUJDODZBbHpOaWtWNVl0clpBTWlKUWJLOEVkZVhrNjNrV0JBWHpsQzhkWEd1anE0N1puSVlLb0ZFMW9OL0ZTOGNYbEZmcDlZWHQ5aU1CZEwyNTBsUlJtaU5HYnloaXRyeVlWQVFvcmkzMlc5YVIwVDhML2FZVkJkZlcrT3kvUXlQWkVtb05LeGhudDJXTlNVRG9VaFo4Wis0cFA3MHBlNWtVUWxiZElWaEFBQURWekNDQTFNd2dnSTdvQU1DQVFJQ0NHVVVrVTNaV0FTMU1BMEdDU3FHU0liM0RRRUJCUVVBTUg4eEN6QUpCZ05WQkFZVEFsVlRNUk13RVFZRFZRUUtEQXBCY0hCc1pTQkpibU11TVNZd0pBWURWUVFMREIxQmNIQnNaU0JEWlhKMGFXWnBZMkYwYVc5dUlFRjFkR2h2Y21sMGVURXpNREVHQTFVRUF3d3FRWEJ3YkdVZ2FWUjFibVZ6SUZOMGIzSmxJRU5sY25ScFptbGpZWFJwYjI0Z1FYVjBhRzl5YVhSNU1CN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Z1FXMWxjbWxqWVM5TWIzTmZRVzVuWld4bGN5STdDZ2tpYjNKcFoybHVZV3d0Y0hWeVkyaGhjMlV0WkdGMFpTSWdQU0FpTWpBeE1pMHdOQzB6TUNBeE5Ub3dOVG8xTlNCRmRHTXZSMDFVSWpzS2ZRPT0iOwoJImVudmlyb25tZW50IiA9ICJTYW5kYm94IjsKCSJwb2QiID0gIjEwMCI7Cgkic2lnbmluZy1zdGF0dXMiID0gIjAiOwp9&lt;/span&gt;'&lt;/span&gt;;

&lt;span class="pl-k"&gt;try&lt;/span&gt; {
  &lt;span class="pl-s1"&gt;&lt;span class="pl-c1"&gt;$&lt;/span&gt;response&lt;/span&gt; = &lt;span class="pl-s1"&gt;&lt;span class="pl-c1"&gt;$&lt;/span&gt;validator&lt;/span&gt;-&amp;gt;&lt;span class="pl-en"&gt;setReceiptData&lt;/span&gt;(&lt;span class="pl-s1"&gt;&lt;span class="pl-c1"&gt;$&lt;/span&gt;receiptBase64Data&lt;/span&gt;)-&amp;gt;&lt;span class="pl-en"&gt;validate&lt;/span&gt;();
  &lt;span class="pl-c"&gt;// $sharedSecret = '1234...'; // Generated in iTunes Connect's In-App Purchase menu&lt;/span&gt;
  &lt;span class="pl-c"&gt;// $response = $validator-&amp;gt;setSharedSecret($sharedSecret)-&amp;gt;setReceiptData($receiptBase64Data)-&amp;gt;validate(); // use setSharedSecret() if for recurring subscriptions&lt;/span&gt;
} &lt;span class="pl-k"&gt;catch&lt;/span&gt; (&lt;span class="pl-smi"&gt;&lt;span class="pl-smi"&gt;Exception&lt;/span&gt;&lt;/span&gt; &lt;span class="pl-s1"&gt;&lt;span class="pl-c1"&gt;$&lt;/span&gt;e&lt;/span&gt;) {
  &lt;span class="pl-k"&gt;echo&lt;/span&gt; &lt;span class="pl-s"&gt;'&lt;span class="pl-s"&gt;got error = &lt;/span&gt;'&lt;/span&gt; . &lt;span class="pl-s1"&gt;&lt;span class="pl-c1"&gt;$&lt;/span&gt;e&lt;/span&gt;-&amp;gt;&lt;span class="pl-en"&gt;getMessage&lt;/span&gt;() . &lt;span class="pl-c1"&gt;PHP_EOL&lt;/span&gt;;
}

&lt;span class="pl-k"&gt;if&lt;/span&gt; (&lt;span class="pl-s1"&gt;&lt;span class="pl-c1"&gt;$&lt;/span&gt;response&lt;/span&gt;-&amp;gt;&lt;span class="pl-en"&gt;isValid&lt;/span&gt;()) {
  &lt;span class="pl-k"&gt;echo&lt;/span&gt; &lt;span class="pl-s"&gt;'&lt;span class="pl-s"&gt;Receipt is valid.&lt;/span&gt;'&lt;/span&gt; . &lt;span class="pl-c1"&gt;PHP_EOL&lt;/span&gt;;
  &lt;span class="pl-k"&gt;echo&lt;/span&gt; &lt;span class="pl-s"&gt;'&lt;span class="pl-s"&gt;Receipt data = &lt;/span&gt;'&lt;/span&gt; . &lt;span class="pl-en"&gt;print_r&lt;/span&gt;(&lt;span class="pl-s1"&gt;&lt;span class="pl-c1"&gt;$&lt;/span&gt;response&lt;/span&gt;-&amp;gt;&lt;span class="pl-en"&gt;getReceipt&lt;/span&gt;()) . &lt;span class="pl-c1"&gt;PHP_EOL&lt;/span&gt;;
  
  &lt;span class="pl-k"&gt;foreach&lt;/span&gt; (&lt;span class="pl-s1"&gt;&lt;span class="pl-c1"&gt;$&lt;/span&gt;response&lt;/span&gt;&lt;/pre&gt;…
&lt;/div&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/aporat/store-receipt-validator" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;h3&gt;
  
  
  In app purchase Cordova plugin
&lt;/h3&gt;

&lt;p&gt;For now, there is one main open source cordova plugin available on Github and supported by the ionic community.&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/j3k0" rel="noopener noreferrer"&gt;
        j3k0
      &lt;/a&gt; / &lt;a href="https://github.com/j3k0/cordova-plugin-purchase" rel="noopener noreferrer"&gt;
        cordova-plugin-purchase
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      In-App Purchase for Cordova on iOS, Android and Windows
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;Cordova Purchase Plugin&lt;/h1&gt;
&lt;/div&gt;
&lt;blockquote&gt;
&lt;p&gt;In-App Purchases for Cordova&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Need professional help and support? &lt;a href="https://github.com/j3k0/cordova-plugin-purchasemailto:hoelt@fovea.cc" rel="noopener noreferrer"&gt;Contact Me&lt;/a&gt;.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Summary&lt;/h2&gt;
&lt;/div&gt;
&lt;p&gt;This plugin allows &lt;strong&gt;In-App Purchases&lt;/strong&gt; to be made from &lt;strong&gt;Cordova, Ionic and Capacitor&lt;/strong&gt; applications.&lt;/p&gt;
&lt;p&gt;It lets you handle in-app purchases on many platforms with a single codebase.&lt;/p&gt;
&lt;p&gt;This is a plugin for the &lt;strong&gt;Apache Cordova&lt;/strong&gt; framework that provides an easy and flexible way to integrate &lt;strong&gt;in-app purchases&lt;/strong&gt; into Cordova-based mobile applications, including popular frameworks such as &lt;strong&gt;Ionic and PhoneGap&lt;/strong&gt;. With this plugin, you can easily add support for in-app purchases of digital content, such as subscriptions, consumables, and non-consumables, using the store-specific purchase APIs provided by the major mobile platforms. The plugin also supports requesting payments through popular payment providers such as &lt;strong&gt;Braintree&lt;/strong&gt;, allowing you to easily accept payments from your users.&lt;/p&gt;
&lt;p&gt;The Cordova-Plugin-Purchase plugin is designed to be easy to use and integrate into your Cordova app, and it provides a…&lt;/p&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/j3k0/cordova-plugin-purchase" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;There is also a wrapper for ionic applications :&lt;br&gt;
&lt;a href="https://ionicframework.com/docs/native/in-app-purchase-2" rel="noopener noreferrer"&gt;&lt;strong&gt;In App Purchase 2 - Ionic Documentation&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;Ionic is the app platform for web developers. Build amazing mobile, web, and desktop apps all with one shared code base…&lt;/em&gt; ionicframework.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Add all these dependencies to your &lt;strong&gt;package.json&lt;/strong&gt; :&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;BILLING_KEY in the plugin's configuration matches your license key for in-app billing should be added manually to your project. This key is found in Services and API in the Google Play Developer Console.&lt;br&gt;
For more informations : &lt;a href="https://github.com/j3k0/cordova-plugin-purchase/wiki/Setup-for-Android-Google-Play#add-android-billing-key" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Google and Apple accounts
&lt;/h3&gt;

&lt;p&gt;To be able to configure your IAP items you need to create an iTunes developer account for IOS app and play store account for Android&lt;br&gt;
&lt;a href="https://developer.apple.com/" rel="noopener noreferrer"&gt;&lt;strong&gt;Apple Developer&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;There's never been a better time to develop for Apple Platforms.&lt;/em&gt; developer.apple.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.android.com/distribute/console" rel="noopener noreferrer"&gt;&lt;strong&gt;Google Play Console&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;Publish your apps and games with the Google Play Console and grow your business on Google Play. Benefit from features…&lt;/em&gt; developer.android.com&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Register your products
&lt;/h2&gt;

&lt;p&gt;Register all your products in the google play console and apple iTunes console.&lt;/p&gt;

&lt;p&gt;For reminder, you have 3 products (10, 50 and 100 credits), so you have to create 3 product IDs: credits_10, credits_50, credits_100&lt;/p&gt;

&lt;p&gt;You can find below how to create your in app products on IOS and Android&lt;br&gt;
&lt;a href="https://support.pressmatrix.com/hc/en-us/articles/202331832-Create-In-App-Products-in-your-Google-Play-Account" rel="noopener noreferrer"&gt;&lt;strong&gt;Create In App Products in your Google Play Account&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;In order to be able to offer a fee-based edition through in-app purchases in your Kiosk-App for Android devices, an…&lt;/em&gt; support.pressmatrix.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.raywenderlich.com/5456-in-app-purchase-tutorial-getting-started" rel="noopener noreferrer"&gt;&lt;strong&gt;In-App Purchase Tutorial: Getting Started&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;Learn how to grow app revenue in this in-app purchase tutorial by allowing users to purchase or unlock content or…&lt;/em&gt; www.raywenderlich.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;All the In App Products should be registered in the app bootstrap, this synchronize the local products data with the remote one.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h2&gt;
  
  
  IAP Product lifecycle
&lt;/h2&gt;

&lt;p&gt;There is many events triggered with the purchase workflow, that allow us to handle and manage errors, success, updates …&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Approved&lt;/strong&gt; means that the product is purchased and the purchase is validated locally, ideally it's the best place to call product.verify() to start server side receipt validation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cancelled&lt;/strong&gt; when the purchase is cancelled, it's time to show an error message.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Error&lt;/strong&gt; when an error occurs during purchase workflow&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Updated&lt;/strong&gt; it's a push based event, when the product informations are updated (price, label, … )&lt;/p&gt;

&lt;h2&gt;
  
  
  Server side verification
&lt;/h2&gt;

&lt;p&gt;When product.verify() is called, an inAppPurchase.validator event is triggered and it's the best place where you can execute your server side receipt verification.&lt;/p&gt;

&lt;p&gt;For our example the creditsProvider.purchase() is responsible for receipt verification and return a status according to the validation results ("success" or "failure")&lt;/p&gt;

&lt;p&gt;Having a success status means that the receipt is valid and now we can finish the transaction by calling product.finish()&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h2&gt;
  
  
  Execute IAP Order
&lt;/h2&gt;

&lt;p&gt;To trigger the purchase workflow above you should call the inAppPurchase.order()&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h2&gt;
  
  
  Turn off listeners
&lt;/h2&gt;

&lt;p&gt;After leaving the view, you should turn off all the event listeners by calling inAppPurchase.off()&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h2&gt;
  
  
  Sandbox and test users
&lt;/h2&gt;

&lt;p&gt;For testing purposes you should define sandbox iCloud users for IOS and add test users for Android.&lt;/p&gt;

&lt;p&gt;Here bellow you can find some links that will help&lt;/p&gt;

&lt;p&gt;Android&lt;br&gt;
&lt;a href="https://developer.android.com/google/play/billing/billing_testing" rel="noopener noreferrer"&gt;&lt;strong&gt;Test Google Play Billing | Android Developers&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;After you finish your static response testing, and you verify that signature verification is working in your…&lt;/em&gt; developer.android.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;IOS&lt;br&gt;
&lt;a href="https://medium.com/@codeneophyte/how-to-create-a-sandbox-tester-account-on-itunes-connect-57eda4247f5c" rel="noopener noreferrer"&gt;&lt;strong&gt;How to create a Sandbox Tester Account on iTunes Connect&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;Creating a Sandbox Tester account in easy thanks to iTunes Connect. A Sandbox account allows you, the developer, to…&lt;/em&gt; medium.com&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Finally a demo App…
&lt;/h2&gt;

&lt;p&gt;Now that you have all what you need to begin your IAP setup, you may probably wish to have a complete demo app with all the steps above… you can find bellow a complete demo app :&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/devHamza" rel="noopener noreferrer"&gt;
        devHamza
      &lt;/a&gt; / &lt;a href="https://github.com/devHamza/iap-demo-ionic-app" rel="noopener noreferrer"&gt;
        iap-demo-ionic-app
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Demo application for in app purchase with ionic / cordova
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="MD"&gt;
&lt;p&gt;This is a demo app for the article : "In App Purchase with Ionic/Cordova"
find more at &lt;a href="https://medium.com/bewizyu" rel="nofollow noopener noreferrer"&gt;https://medium.com/bewizyu&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;



&lt;/div&gt;
&lt;br&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/devHamza/iap-demo-ionic-app" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;br&gt;


&lt;p&gt;&lt;a href="https://www.bewizyu.com/make" rel="noopener noreferrer"&gt;&lt;strong&gt;BEWIZYU Technology&lt;/strong&gt; &lt;em&gt;Développement, expertise sur plateformes à usage mobile&lt;/em&gt; www.bewizyu.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>android</category>
      <category>ios</category>
      <category>cordova</category>
      <category>ionic</category>
    </item>
  </channel>
</rss>
