Created
October 29, 2017 20:55
-
-
Save iloveitaly/3a164ca0ff22ac9ed7ea4fe86489b53c 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 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