Replace MyShop/www/js/index.js
with the following code:
var app = {
initialize: function() {
this.bindEvents();
},
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
onDeviceReady: function() {
app.receivedEvent('deviceready');
},
receivedEvent: function(id) {
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
console.log('Received Event: ' + id);
app.initPaymentUI();
},
initPaymentUI : function () {
var clientIDs = {
"PayPalEnvironmentProduction": "YOUR_PRODUCTION_CLIENT_ID",
"PayPalEnvironmentSandbox": "YOUR_SANDBOX_CLIENT_ID"
};
PayPalMobile.init(clientIDs, app.onPayPalMobileInit);
},
onSuccesfulPayment : function(payment) {
console.log("payment success: " + JSON.stringify(payment, null, 4));
},
onCardIOComplete: function(card) {
console.log("Card Scanned success: " + JSON.stringify(card, null, 4));
},
onAuthorizationCallback : function(authorization) {
console.log("authorization: " + JSON.stringify(authorization, null, 4));
},
createPayment : function () {
var paymentDetails = new PayPalPaymentDetails("50.00", "0.00", "0.00");
var payment = new PayPalPayment("50.00", "USD", "Awesome Sauce", "Sale", paymentDetails);
return payment;
},
configuration : function () {
var config = new PayPalConfiguration({merchantName: "My test shop", merchantPrivacyPolicyURL: "https://mytestshop.com/policy", merchantUserAgreementURL: "https://mytestshop.com/agreement"});
return config;
},
onPrepareRender : function() {
var buyNowBtn = document.getElementById("buyNowBtn");
var buyInFutureBtn = document.getElementById("buyInFutureBtn");
var profileSharingBtn = document.getElementById("profileSharingBtn");
var cardScanBtn = document.getElementById("cardScanBtn");
buyNowBtn.onclick = function(e) {
PayPalMobile.renderSinglePaymentUI(app.createPayment(), app.onSuccesfulPayment, app.onUserCanceled);
};
buyInFutureBtn.onclick = function(e) {
PayPalMobile.renderFuturePaymentUI(app.onAuthorizationCallback, app.onUserCanceled);
};
profileSharingBtn.onclick = function(e) {
PayPalMobile.renderProfileSharingUI(["profile", "email", "phone", "address", "futurepayments", "paypalattributes"], app.onAuthorizationCallback, app.onUserCanceled);
};
cardScanBtn.onclick = function(e) {
CardIO.scan({
"requireExpiry": true,
"requireCVV": false,
"requirePostalCode": false,
"restrictPostalCodeToNumericOnly": true
},
app.onCardIOComplete,
app.onUserCanceled
);
};
},
onPayPalMobileInit : function() {
PayPalMobile.prepareToRender("PayPalEnvironmentSandbox", app.configuration(), app.onPrepareRender);
},
onUserCanceled : function(result) {
console.log(result);
}
};
app.initialize();