Skip to content

Instantly share code, notes, and snippets.

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/3a164ca0ff22ac9ed7ea4fe86489b53c to your computer and use it in GitHub Desktop.
Save iloveitaly/3a164ca0ff22ac9ed7ea4fe86489b53c to your computer and use it in GitHub Desktop.
function isWebServicesContext() {
var context = nlapiGetContext();
var executionContext = context.getExecutionContext();
return executionContext == 'webservices';
}
function isEmpty(obj) {
return obj === undefined || obj === null || obj === "";
}
function contains(str, searchString) {
return str.indexOf(searchString) != -1;
}
var SUITESYNC_TRANSACTION_ID_FIELD = 'custbody_suitesync_authorization_code';
function afterSubmit(type) {
if(type != 'edit' && type != 'create') {
return
}
if(!isWebServicesContext()) {
return
}
var oldRecord = nlapiGetOldRecord();
var oldTransactionID = oldRecord.getFieldText(SUITESYNC_TRANSACTION_ID_FIELD);
var currentTransactionID = nlapiGetFieldText(SUITESYNC_TRANSACTION_ID_FIELD);
var memo = nlapiGetFieldText('memo');
// if automatic (i.e. scheduled) payment has failed the transaction ID field is empty, but there is an error message from the integation
if(isEmpty(currentTransactionID) && contains(memo, 'Stripe:')) {
automaticPaymentFailure();
}
// if using auth-capture, the transaction ID field should always contain a Stripe ID if the integration is updating the status of the capture
if(!isEmpty(oldTransactionID) && currentTransactionID == oldTransactionID && contains(memo, 'Stripe:')) {
captureFailureOrReauthorizationFailure();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment