j3k0 / cordova-plugin-purchase

In-App Purchase for Cordova on iOS, Android and Windows
https://purchase.cordova.fovea.cc
1.29k stars 532 forks source link

[IOS] Restore button #1208

Open antuan10 opened 3 years ago

antuan10 commented 3 years ago

system info Cordova:

Cordova CLI : 10.0.0 Cordova Platforms : ios 6.1.0 Cordova Plugins : cordova-plugin-code-push, cordova-plugin-network-information

Hello, I am a beginner programmer. I have been able to implement the in-app purchase in my app using cordova and the inapp.js and index.html codes. Everything works correctly. But I am unable to put a Restore button. I have spent many hours trying but I don't know how to do it. Any suggestion?

//**inapp.js**

document.addEventListener('deviceready', initStore);

function initStore() {

  if (!window.store) {
    console.log('Store not available');
    return;
  }

  store.verbosity = store.INFO;
  store.register({
    id:    'nonconsumable1',
    type:   store.NON_CONSUMABLE
  });

  store.error(function(error) {
    console.log('ERROR ' + error.code + ': ' + error.message);
  });

  store.when('nonconsumable1').updated(refreshProductUI);
  store.when('nonconsumable1').approved(function(p) {
    p.verify();
  });
  store.when('nonconsumable1').verified(finishPurchase);

  store.refresh();
}

function refreshProductUI(product) {
  const info = product.loaded
  ? `<h1>${product.title}</h1>` +
    `<p>${product.description}</p>` +
    `<p>${product.price}</p>`
  : '<p>Retrieving info...</p>';
  const button = product.canPurchase
  ? '<button onclick="purchaseNonConsumable1()">Inicia Compra / Buy Now</button>'
  : '';
  const el = document.getElementById('nonconsumable1-purchase');
  el.innerHTML = info + button;

  const restorePurchase = () => `
      <div class="container">
        <div class="row">
        ` + button('Restore Purchases', 'store.refresh()') + `
        </div>
      </div>`;

}

function purchaseNonConsumable1() {
  store.order('nonconsumable1');
}

function finishPurchase(p) {
  window.localStorage.unlocked = 'YES';
  p.finish();
}

index.html

 <!DOCTYPE html>
<html>
 <head> 
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"/>
        <meta http-equiv="Content-Security-Policy" content="default-src https://codepush.appcenter.ms 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *" />
        <title>Camino</title>

        <!--grupo CSS-->
        <link href="css/index.css" type="text/css" rel="stylesheet"/>
        <link href="css/jquery.mobile-1.4.5.min.css" type="text/css" rel="stylesheet"/>   
        <link href="css/temait8.css" type="text/css" rel="stylesheet"/>

        <!--grupo JavaScript-->
        <script src="js/inapp.js" type="text/javascript"></script>
        <script src="js/index.js" type="text/javascript"></script>
        <script src="js/jquery-1.11.3.min.js" type="text/javascript"></script>
        <script src="js/jquery.mobile-1.4.5.min.js" type="text/javascript"></script>
        <script type="text/javascript" src="cordova.js"></script>
 </head>
 <body>

      <center><div id="nonconsumable1-purchase">Please wait...</div></center>

 </div>
 </div>
 </body>
 </html>
Dexus commented 3 years ago

Add a button that use the


store.refresh()

Again. And it will restore.

antuan10 commented 3 years ago

Thank you very much for answering. But I have another problem. The above code works perfectly on android but does not work on ios. In ios the button does not work. And in the xcode it does not give me any error, simply the button that I have in the index.html does not react. Any idea why?

Dexus commented 3 years ago

Maybe you review your code and look for the const button and also for the function some lines later button('Restore Purchases', 'store.refresh()') this looks like the problem ?

antuan10 commented 2 years ago

Hi Dexux, my programming level is very basic. I have been able to put the inapp purchase in my cordova app after literally hundreds of hours. The code works fine on android but not on ios. It may be something simple but I don't know what it can be. When saying that the problem is "he const button and also for the function some lines later button('Restore Purchases', 'store.refresh()') ". The truth is that I don't know how to make those modifications in the code. Could you tell me how to write the code? Sorry for asking too much, but it is important for me to get the code to work after so many hours invested and to be so close to getting it

Dexus commented 2 years ago

If you need professional help you have to pay for it.

antuan10 commented 2 years ago

Hi Dexus, you are absolutely right. The problem I find is that it is difficult to find someone for a small and very specific problem like this. Would you do this job for money?

Dexus commented 2 years ago

You can find contact details at www.deineagentur.com, I will be happy to make you an offer. Please make sure that you can provide Git access if you want to hire me. No ZIP files or downloads will be made.

antuan10 commented 2 years ago

Hello Dexus, did you receve my mail?

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.