Skip to content

Instantly share code, notes, and snippets.

@iloveitaly
Created February 8, 2018 02:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iloveitaly/b9eb91bbf3a10606f58e5d4140f8dd22 to your computer and use it in GitHub Desktop.
Save iloveitaly/b9eb91bbf3a10606f58e5d4140f8dd22 to your computer and use it in GitHub Desktop.
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