Last active
January 15, 2019 11:50
-
-
Save iloveitaly/20df1b23dc94153bcb6b424c808a9686 to your computer and use it in GitHub Desktop.
Generate a Stripe-powered payment link for Invoices & SalesOrders using SuiteScript http://SuiteSync.io
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
/* | |
Author: <mike@suitesync.io> | |
Description: Generates the Stripe Payment Link for Invoices & Orders and saves it to a field | |
Link: https://gist.github.com/iloveitaly/20df1b23dc94153bcb6b424c808a9686 | |
Installation: | |
Create Custom Field: | |
1. https://dashboard.suitesync.io/docs/netsuite-configuration#creating-the-stripe-invoice-payment-link-custom-fie | |
2. Make sure the field has `Store Value` checked and is a free-form text field | |
Create Script Deployment: | |
1. https://system.sandbox.netsuite.com/app/common/scripting/uploadScriptFile.nl | |
2. User Event | |
3. Name: Stripe Payment Link Creator | |
4. ID: _create_stripe_payment_link | |
5. After Submit: afterSubmit | |
6. Deployments: Invoice & SalesOrder. Event Type: Create. Ensure accessible to all roles and executes as admin. | |
* Note you cannot create a deployment for the SO & Invoice at the same time when creating the script record. | |
NetSuite will throw an error. You must create the deployments for these separately | |
7. Update `STRIPE_ACCOUNT_ID` in this script to match your Stripe account ID | |
*/ | |
var STRIPE_ACCOUNT_ID = 'acct_'; | |
var BASE_URL = 'https://app.suitesync.io/payments/' + STRIPE_ACCOUNT_ID + '/'; | |
var STRIPE_PAYMENT_LINK_FIELD = 'custbody_stripe_invoice_payment_link'; | |
function afterSubmit() { | |
if(type != 'create') { | |
return; | |
} | |
var recordType = nlapiGetRecordType(); | |
var recordId = nlapiGetRecordId(); | |
var paymentLink = generateStripePaymentLink(recordType, recordId); | |
nlapiSubmitField(recordType, recordId, STRIPE_PAYMENT_LINK_FIELD, paymentLink); | |
} | |
function generateStripePaymentLinkFromRecord(nsRecord) { | |
return generateStripePaymentLink(nsRecord.getRecordType(), nsRecord.getId()); | |
} | |
function generateStripePaymentLink(type, id) { | |
return BASE_URL + type + '/' + id; | |
} | |
if(nlapiGetContext().getExecutionContext() == 'debugger') { | |
generateStripePaymentLink(nlapiLoadRecord('invoice', 14056546)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment