Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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