j3k0 / cordova-non-renewing-subscription

Simple API for Non-Renewing Subscriptions based on Fovea's Cordova Purchase Plugin
MIT License
19 stars 6 forks source link

subscribe doesn't work #24

Open Macfa opened 3 years ago

Macfa commented 3 years ago

hi I build a subscription using cordova I've following your code ( https://github.com/j3k0/cordova-non-renewing-subscription ) click a manage your subscription button and "subscribe now!" it show 2 items what i registerd and I choose 1 item show "loading.." popup and that's all I read document again but I don't know what do i do.. would you help me what i wrong ?

index.html

`function OpenInAppPurchase() { // Create some dummy HTML page (for testing). // Your content, somewhere, has a "Manage Subscription" button, right? document.getElementById('DivPageClassRegisterPurchaseHTML').innerHTML = '

Manage your subscription

';

// Make sure this button opens the subscription manager:
// nonRenewing.openSubscriptionManager();

var button = document.getElementsByClassName('manage-subscription')[0];
button.addEventListener('click', function(event) {
    console.log('showMainScreen -> openSubscriptionManager');
    event.preventDefault();
    nonRenewing.openSubscriptionManager();
});

function doSomething() {

    // Some places in your code, you probably
    // need to know if the user is subscribed.

    nonRenewing.getStatus(function(error, status) {
        if (error) {
            console.error("Failed to load subscription status: " + error);
            return;
        }
        console.log("Is Subscribed: " + status.subscriber);
        console.log("Expiry Date:   " + status.expiryDate);
    });
};

}`

app_init.js

`var app = { initialize: function() { document.addEventListener('deviceready', this.onDeviceReady.bind(this), false); document.addEventListener("resume", onDviceResume, false); }, onDeviceReady: function() {

    this.receivedEvent('deviceready');

    nonRenewing.initialize({
        verbosity: store.DEBUG,
        products: [{
            id: 'kr.test.testapp.1month',
            duration: 2592000
        }, {
            id: 'kr.test.testapp.3month',
            duration: 7776000
        }]
    });`

here error code

`2021-01-14 22:40:50.851170+0900 testapp[22283:1393277] InAppPurchase[objc]: processPendingTransactionUpdates 2021-01-14 22:40:51.026580+0900 testapp[22283:1393102] InAppPurchase[js]: load ok: { valid:[{"id":"kr.test.testapp.1month","description":null,"introPrice":null,"introPricePaymentMode":null,"billingPeriodUnit":"Day","countryCode":"KR","introPricePeriodUnit":null,"discounts":[],"title":null,"price":"₩79,000","billingPeriod":0,"group":null,"priceMicros":79000000000,"currency":"KRW","introPricePeriod":null,"introPriceMicros":null},{"id":"kr.test.testapp.3month","description":" 화상수업을 3달 간 받을 수 있는 자동갱신이 안되는 아이템입니다","introPrice":null,"introPricePaymentMode":null,"billingPeriodUnit":"Day","countryCode":"KR","introPricePeriodUnit":null,"discounts":[],"title":" 화상수업 3달 구독","price":"₩249,000","billingPeriod":0,"group":null,"priceMicros":249000000000,"currency":"KRW","introPricePeriod":null,"introPriceMicros":null}] invalid:[] } 2021-01-14 22:40:51.047957+0900 testapp[22283:1393102] [store.js] DEBUG: ios -> products loaded 2021-01-14 22:40:51.061813+0900 testapp[22283:1393102] [nonRenewing.js] Product updated: kr.test.testapp.1month (registered) 2021-01-14 22:40:51.064330+0900 testapp[22283:1393102] [nonRenewing.js] Product updated: kr.test.testapp.3month (registered) 2021-01-14 22:40:51.069204+0900 testapp[22283:1393102] [store.js] DEBUG: ios -> product kr.test.testapp.1month is valid (kr.test.testapp.1month) 2021-01-14 22:40:51.072093+0900 testapp[22283:1393102] [store.js] DEBUG: ios -> owned? false 2021-01-14 22:40:51.073343+0900 testapp[22283:1393102] [store.js] DEBUG: state: kr.test.testapp.1month -> valid 2021-01-14 22:40:51.073509+0900 testapp[22283:1393102] [nonRenewing.js] Product updated: kr.test.testapp.1month (valid) 2021-01-14 22:40:51.074844+0900 testapp[22283:1393102] [nonRenewing.js] Product updated: kr.test.testapp.1month (valid) 2021-01-14 22:40:51.075809+0900 testapp[22283:1393102] [store.js] DEBUG: ios -> product kr.test.testapp.3month is valid (kr.test.testapp.3month) 2021-01-14 22:40:51.077705+0900 testapp[22283:1393102] [store.js] DEBUG: ios -> owned? false 2021-01-14 22:40:51.079157+0900 testapp[22283:1393102] [store.js] DEBUG: state: kr.test.testapp.3month -> valid 2021-01-14 22:40:51.083768+0900 testapp[22283:1393102] [nonRenewing.js] Product updated: kr.test.testapp.3month (valid) 2021-01-14 22:40:51.087552+0900 testapp[22283:1393102] [nonRenewing.js] Product updated: kr.test.testapp.3month (valid) 2021-01-14 22:40:51.104059+0900 testapp[22283:1393102] ERROR Internal navigation rejected - not set for url='about:blank' 2021-01-14 22:40:51.269709+0900 testapp[22283:1393102] [store.js] DEBUG: update() 2021-01-14 22:40:51.270683+0900 testapp[22283:1393102] InAppPurchase[js]: loading appStoreReceipt 2021-01-14 22:40:51.271258+0900 testapp[22283:1393102] InAppPurchase[objc]: appStoreReceipt: 2021-01-14 22:40:51.302391+0900 testapp[22283:1393102] InAppPurchase[js]: infoPlist: kr.test.testapp,1.5.9,22642688,???? 2021-01-14 22:40:51.304287+0900 testapp[22283:1393102] [store.js] DEBUG: state: kr.test.testapp -> 2021-01-14 22:40:51.304498+0900 testapp[22283:1393102] [store.js] DEBUG: state: kr.test.testapp -> registered 2021-01-14 22:40:51.304595+0900 testapp[22283:1393102] [store.js] DEBUG: ios -> product kr.test.testapp registered and owned 2021-01-14 22:40:51.304684+0900 testapp[22283:1393102] [nonRenewing.js] Product updated: kr.test.testapp (registered) 2021-01-14 22:40:51.304807+0900 testapp[22283:1393102] [nonRenewing.js] Product updated: kr.test.testapp (registered) 2021-01-14 22:40:51.304895+0900 testapp[22283:1393102] [store.js] DEBUG: state: kr.test.testapp -> approved 2021-01-14 22:40:51.304975+0900 testapp[22283:1393102] [nonRenewing.js] Product updated: kr.test.testapp (approved) 2021-01-14 22:40:51.305141+0900 testapp[22283:1393102] [store.js] DEBUG: product -> defer finishing kr.test.testapp 2021-01-14 22:40:51.305567+0900 testapp[22283:1393102] [store.js] DEBUG: state: kr.test.testapp -> approved 2021-01-14 22:40:51.305678+0900 testapp[22283:1393102] [nonRenewing.js] Product updated: kr.test.testapp (approved) 2021-01-14 22:40:51.305788+0900 testapp[22283:1393102] [store.js] DEBUG: product -> defer finishing kr.test.testapp 2021-01-14 22:40:51.307061+0900 testapp[22283:1393102] [store.js] DEBUG: product -> finishing kr.test.testapp 2021-01-14 22:40:51.307191+0900 testapp[22283:1393102] [store.js] DEBUG: state: kr.test.testapp -> finished 2021-01-14 22:40:51.307282+0900 testapp[22283:1393102] [store.js] DEBUG: ios -> finishing kr.test.testapp (a application) 2021-01-14 22:40:51.307478+0900 testapp[22283:1393102] [store.js] DEBUG: state: kr.test.testapp -> owned 2021-01-14 22:40:51.308823+0900 testapp[22283:1393102] [nonRenewing.js] Product updated: kr.test.testapp (owned) 2021-01-14 22:40:51.309712+0900 testapp[22283:1393102] [nonRenewing.js] Product updated: kr.test.testapp (owned) 2021-01-14 22:40:51.309839+0900 testapp[22283:1393102] [store.js] DEBUG: product -> finishing kr.test.testapp 2021-01-14 22:40:51.310883+0900 testapp[22283:1393102] [store.js] DEBUG: state: kr.test.testapp -> finished 2021-01-14 22:40:51.311908+0900 testapp[22283:1393102] [store.js] DEBUG: ios -> finishing kr.test.testapp (a application) 2021-01-14 22:40:51.313475+0900 testapp[22283:1393102] [store.js] DEBUG: state: kr.test.testapp -> owned 2021-01-14 22:40:51.314637+0900 testapp[22283:1393102] [nonRenewing.js] Product updated: kr.test.testapp (owned) 2021-01-14 22:40:51.314850+0900 testapp[22283:1393102] [nonRenewing.js] Product updated: kr.test.testapp (owned)

2021-01-14 22:40:55.768700+0900 testapp[22283:1393102] The preference key "AutoHideSplashScreen" is not defined and will default to "TRUE" 2021-01-14 22:41:01.541928+0900 testapp[22283:1393102] showMainScreen -> openSubscriptionManager 2021-01-14 22:41:03.016516+0900 testapp[22283:1393102] [nonRenewing.js] Event renew 2021-01-14 22:41:04.473551+0900 testapp[22283:1393102] [nonRenewing.js] Event buy-1 2021-01-14 22:41:04.473886+0900 testapp[22283:1393102] [nonRenewing.js] Purchase product at index 1`

Macfa commented 3 years ago

add index.html header section

<meta http-equiv="Content-Security-Policy" content="default-src * 'self' 'unsafe-inline' 'unsafe-eval'; connect-src * https://validator.fovea.cc; style-src * 'self' 'unsafe-inline'; media-src *">

jussihuotari commented 3 years ago

I think this is related to https://github.com/j3k0/cordova-plugin-purchase/issues/995

You'd want to check if the window.store.ready() becomes true at all. I think the problem is that at some point Apple added a new product type, which is not recognized by cordova-non-renewing-subscription and thus the product is finished too early, see p.finish():

https://github.com/j3k0/cordova-non-renewing-subscription/blob/cf86f597779f873544bbfa6c085454e0a28b6e91/cordova-non-renewing-subscription.js#L319-L325

A possible fix may be to check the type before finishing. I didn't test this thoroughly.

  if (!nrProduct) {
      if (p.type !== window.store.APPLICATION) {
        p.finish();
      }
     return;
  }
Macfa commented 3 years ago

@jussihuotari I put your code into my project then, works Thanks

josem32 commented 9 months ago

@jussihuotari worked like a charm