PeterStaev / nativescript-purchase

:moneybag: A NativeScript plugin for making in-app purchases!
Apache License 2.0
83 stars 28 forks source link

JS ERROR TypeError: null is not an object (evaluating 'nativeValue.transactionState') #58

Closed p-3 closed 5 years ago

p-3 commented 5 years ago

i am getting

JavaScript error: file:///app/tns_modules/nativescript-purchase/transaction/transaction.js:27:28: JS ERROR TypeError: null is not an object (evaluating 'nativeValue.transactionState') *** JavaScript call stack:

after first successfully purchase has made on IOS.

The app crashes after this message.

any clue on this?

PeterStaev commented 5 years ago

Hey @p-3 , sadly no idea what might be wrong and no idea how your workflow looks like. It will be best you debug your whole workflow and see what might be wrong.

p-3 commented 5 years ago

thanks for fast reply..

p-3 commented 5 years ago

nativeValue.transactionState seems to be NULL some times on

switch (nativeValue.transactionState)

in nativescript-purchase/transaction/transaction.ios.ts .. It seems to work if I add null check before but I would be more nice to know why it's null in some cases.

p-3 commented 5 years ago

I did try to modify the transpiled js file to..

/*! ***** Copyright (c) 2018 Tangra Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ***** / "use strict"; function export(m) { for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; } Object.defineProperty(exports, "esModule", { value: true }); var transaction_common_1 = require("./transaction-common"); __export(require("./transaction-common")); var Transaction = (function (_super) { __extends(Transaction, _super); function Transaction(nativeValue) { var _this = _super.call(this, nativeValue) || this; if (nativeValue && nativeValue.transactionState) { switch (nativeValue.transactionState) { case 4 / Deferred /: _this.transactionState = transaction_common_1.TransactionState.Deferred; break; case 2 / Failed /: _this.transactionState = transaction_common_1.TransactionState.Failed; break; case 1 / Purchased /: _this.transactionState = transaction_common_1.TransactionState.Purchased; break; case 0 / Purchasing /: _this.transactionState = transaction_common_1.TransactionState.Purchasing; break; case 3 / Restored /: _this.transactionState = transaction_common_1.TransactionState.Restored; _this.originalTransaction = new Transaction(nativeValue.originalTransaction); break; } _this.productIdentifier = nativeValue.payment.productIdentifier; _this.transactionIdentifier = nativeValue.transactionIdentifier; if (nativeValue.transactionDate) { _this.transactionDate = nativeValue.transactionDate; // NSDate will automatically be bridged to date } if (nativeValue.transactionReceipt) { _this.transactionReceipt = nativeValue.transactionReceipt.base64EncodedStringWithOptions(1 / Encoding64CharacterLineLength */); } return _this; } } return Transaction; }(transaction_common_1.TransactionBase)); exports.Transaction = Transaction;

and everything seems to work for me, do you see any issues to have the NULL check before the switch case?

PeterStaev commented 5 years ago

Hey @p-3 , thanks you for tracing this! I guess the null check is ok, but not sure how to treat such NULL state transaction and I can't find any reference in what situations the state can end up null. When you say everything works, in your workflow how do you treat such null state transactions? You just skip them?

p-3 commented 5 years ago

The easiest way to get this error is by create a test flight subscription which is valid while the test flight version of app is active. and you get this when you upload new app version to TestFlight and remove the old one.

but I also have get this error with one time purchase products also but its also harder to get the error every time.