Created
February 8, 2018 02:19
-
-
Save iloveitaly/b9eb91bbf3a10606f58e5d4140f8dd22 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function log(msg) { | |
nlapiLogExecution('DEBUG', msg); | |
} | |
function startsWith(str, searchString) { | |
return str.indexOf(searchString) === 0; | |
} | |
function isEmpty(obj) { | |
return obj === undefined || obj === null || obj === ""; | |
} | |
function triggerStripePayment(invoiceInternalID) { | |
var invoiceCustomerID = nlapiLookupField('invoice', invoiceInternalID, 'entity') | |
var stripeCustomerID = nlapiLookupField('customer', invoiceCustomerID, 'externalid'); | |
if(isEmpty(stripeCustomerID)) { | |
log("no external ID detected, no Stripe customer exists"); | |
return null; | |
} | |
if(startsWith(stripeCustomerID, 'cus_')) { | |
nlapiSubmitField('invoice', invoiceInternalID, 'custbody_suitesync_authorization_code', stripeCustomerID); | |
} else { | |
log("external ID does not look like a Stripe customer ID: " + stripeCustomerID) | |
} | |
} | |
if(nlapiGetContext().getExecutionContext() == 'debugger') { | |
triggerStripePayment(14441564); | |
} | |
// allows you set a breakpoint at the end of the script | |
'debug'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment