Skip to content

Instantly share code, notes, and snippets.

@troscoe
Last active December 16, 2015 06:19
Show Gist options
  • Save troscoe/5390922 to your computer and use it in GitHub Desktop.
Save troscoe/5390922 to your computer and use it in GitHub Desktop.
singleton model for #tialloy InApp purchases for iOS using StoreKit module
var Storekit = require('ti.storekit');
Storekit.receiptVerificationSandbox = true;
Storekit.receiptVerificationSharedSecret = "********************************";
var verifyingReceipts = false;
exports.definition = {
config: {
"columns": {
"title":"TEXT",
"description":"TEXT",
"productid":"TEXT",
"appleid":"TEXT",
"purchased":"integer"
},
"adapter": {
"type": "sql",
"collection_name": "purchases"
}
},
"defaults" : {
"title":"",
"description":"",
"productid":"",
"appleid":"",
"purchased":0
},
extendModel: function(Model) {
_.extend(Model.prototype, {
requestProduct: function(identifier, success) {
Storekit.requestProducts([identifier], function (evt) {
if (!evt.success) {
alert('ERROR: We failed to talk to Apple!');
}
else if (evt.invalid) {
alert('ERROR: We requested an invalid product!');
}
else {
success(evt.products[0]);
}
});
}
});
return Model;
},
extendCollection: function(Collection) {
_.extend(Collection.prototype, {
// extended functions and properties go here
});
return Collection;
}
}
@troscoe
Copy link
Author

troscoe commented Apr 15, 2013

Thinking about changing "appleid" to "vendorid" to not make it Apple specific but haven't taken a look at Android InApp purchases yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment