Here are some examples to help you integrate your application with Stripe to use the NetSuite integration.
The code examples below are designed to provide boilerplate code to demonstrate how the Stripe NetSuite integration works, and how to handle unique business processes using SuiteSync. All of the examples can be run by entering your Stripe API key and running the ruby code. Here's how:
- Install the stripe ruby gem. The example code can easily be ported to other languages.
- Replace the test key in the source files with your Stripe account's test key. For some scripts, you may need to enter your NetSuite credentials.
ruby the_example.rbat the terminal
Creating a NetSuite Customer with Stripe
This example demonstrates this customer translation functionality:
- Linking an existing NetSuite customer with an existing customer
- Linking an existing NetSuite customer with a new customer
- Using metadata to set NetSuite field data
Creating & Paying a NetSuite Invoice with Stripe Checkout
You can create a NetSuite invoice using Stripe, and pay it off using Stripe Checkout, without interfacing with NetSuite directly.
Creating a Stripe Subscription
A simple example demonstrating how to create a Stripe Subscription and pass custom data to NetSuite.
Creating a Subscription with Avalara Tax Information
An example demonstrating how to create a Stripe Subscription which includes the necessary information for Avalara's pre-built tax integration.
Create a Subscription from Customer-entered Credit Card Information
Example of a customer-facing checkout form built with Stripe checkout which creates a Stripe Subscription.
Using Stripe Subscriptions to Manage Complex Usage Based Billing
You can use Stripe Subscriptions to manage usage based billing. Here's an example demonstrating how to leverage Stripe webhooks to calculate usage based billing amounts in your application and push them to Stripe.
Using Stripe Subscriptions to Manage Simple Usage Billing
Paying an Existing NetSuite Invoice with Stripe
You can pay an existing NetSuite invoice with Stripe by passing the NetSuite Invoice ID to Stripe. The integration applies a CustomerPayment against the invoice you specify.
Creating a NetSuite using SuiteTalk and paying it with Stripe
Here's an example of how to create a NetSuite invoice using the SuiteTalk API and then paying that invoice off using a Stripe charge.
Payment Installments Against a Single NetSuite Invoice
You can use Stripe Subscriptions to create payment installments against a single NetSuite invoice.
Attaching a Stripe Charge as a CustomerDeposit against a SalesOrder
You can attach a Stripe charge against a SalesOrder as a customer deposit by specifying the internal ID of the SalesOrder.
Creating a Standalone Invoice with Stripe
The integration supports translating subscription-created invoices with revenue recognition, but it also supports translating one-off invoices creating in Stripe. This example demonstrates how to create a customer and a standalone invoice with a custom SKU.
If Stripe's subscription billing isn't workable for your use-case, but you want to use the Stripe NetSuite integration to create invoices in NetSuite, creating a standalone invoice might work for you.
Collecting Payment for a Standalone Payment with Stripe Checkout
This example demonstrates how to use Stripe Checkout to collect payment credentials, and then create a Stripe Invoice and Charge the collected credit card.
Collecting Payment for a Subscription with Stripe Checkout
This example demonstrates how to use Stripe Checkout to collect payment credentials, and then create a Stripe Subscription with the collected credit card.
Testing Stripe disputes
Authorizing a Charge with Stripe Checkout for Capture from NetSuite
Often in eCommerce flows you'll want to authorize a charge during checkout but only later capture the charge once the order has been fulfilled in NetSuite. Here's an example of how to implement this using Stripe and the authorization-capture workflow:
ACH debit (and other alternative payment methods) is fully supported in the integration. This example will create a bitcoin payments in your Stripe test environment to allow you to inspect the resulting customer payment in NetSuite.
Creating Sales Orders with Stripe Orders API (Relay)
This example demonstrates how the integration's order integration works:
- Creates a SKU, which is translated into a NonInventoryItem in NetSuite
- Creates a Order with a single line item
- Waits for the translation to complete, and returns the NetSuite SalesOrder internal ID.
Copy Stripe Subscription Metadata to Subscription Invoice Metadata
Stripe Subscriptions create a Stripe Invoice every plan period. In some cases, copying metadata from the subscription to the invoice is helpful for setting standard or custom fields on the invoice. For instance, if there's an internal subscription order number that you want on every subsequent invoice, you can copy this number from the subscription metadata to the invoice metadata so the number can flow to the NetSuite invoice.
Connect Stripe Plans to Existing NetSuite Items
If you are using Stripe Subscriptions you can connect your Stripe Plans to existing items in NetSuite using the following migration tool.
Link Stripe Customers to NetSuite Customers by Email
If you've been using NetSuite for a while, but are just getting started with Stripe, you'll want to link your Stripe customers to the associated NetSuite customer. Here's an example of linking Stripe customers with NetSuite customers by using email as the linking key between the two systems.
Link Stripe Customers to NetSuite Customers Using a CSV
If you have existing NetSuite customers that you'd like to Stripe customers you can create a mapping between the two systems and use this script to link Stripe & NetSuite customers together.
Link Stripe Customers to NetSuite Customers Using Card Details
When migrating card data from another processor to Stripe the data provided by the old processor can sometimes be spotty. Use this script to match Stripe customers to a CSV row using card details (last4, zip, expiration, etc) and save additional customer data to Stripe from that CSV file.
Pay Due NetSuite Invoices Using Stripe
You can leverage SuiteSync to auto-pay invoices in NetSuite using Stripe. SuiteSync has built-in functionality to handle this, but you can also customize the example code below to fit your exact use-case.
Customer NetSuite Invoices created from Stripe Subscriptions
Each billing period a Stripe subscription creates an invoice in NetSuite. You can customize the data on that invoice by adding metadata to the Stripe subscription to be copied to each subsequent invoice.
Find Closed and Unpaid, or Forgiven Invoices
If you choose not to automatically close out unpaid or forgiven Stripe invoices in NetSuite, you will want to create a custom process around handled this "bad debt". Here's a starting point you can use to pull identify these invoices in Stripe.
Remove Metadata Keys
The integration adds metadata keys to Stripe records.. If you are developing customized integrations leveraging SuiteSync, it may be helpful to wipe all of the metadata keys that SuiteSync uses in order to re-run integration tests. Below is a script that wipes metadata keys from your Stripe account.
Demonstrate Stripe Subscriptions Edge Case
There are many edge cases that can occur when processing subscription payments. Below is a script that generates various subscription states so you inspect how they look in your NetSuite account.
Use Stripe Subscriptions to Create a Payment Plan for a NetSuite Invoice
Create an Invoice with Payment Terms in Stripe
Change Plans & Issue a Refund with Stripe
Create a Payment Link Dynamically using SuiteScript
SuiteSync provides a set of pre-built open source SuiteScripts to help with common use cases that we've come across. These scripts are well documented, and you can easily install them in your NetSuite account. However, we can't guarantee that they will work with the customizations that exist in your NetSuite account and we can't help maintain or modify them to fit specific business requirements.
Create SalesOrder from Invoice
By default in NetSuite a SalesOrder must be created first and then the SalesOrder can be billed, which creates an invoice. This script adds a
beforeSubmit user event script which dynamically creates the SalesOrder right before the invoice is saved from the contents of the invoice. In other words, you can send over just an invoice to NetSuite and this script generates a SalesOrder for you.
You'll need to customize this script to fit your needs and be sure to test this before every major NetSuite release: this is not something officially supported or maintained by SuiteSync.
Auto-bill NetSuite SalesOrders When a CustomerDeposit is Added
This script automatically bills a sales order, creating an invoice, when there are enough customer deposits attached to the sales order to mark the resulting invoice as "Paid in Full"
Here are some important details about how the script works:
- It is aware of NetSuite usage governance and will automatically retry if the script runs out of "usage credits"
- The script only processes Sales Orders which are Pending Billing. This means that the script does not process the same sales order twice—once it is billed, it is not reprocessed.
- Your NetSuite Sales Order form must create a invoice, not a cash sale, when billed.
SuiteScript to Copy Transaction Fields to a Payment or Refund Record in NetSuite
This is a SuiteScript which copies fields from a Invoice, CreditMemo, or other transaction to a corresponding payment record applied to that transaction. This is helpful if you want to use the same department or class on a payment or refund that was assigned to a invoice, credit memo, etc.
Auto-apply Customer Payments When a NetSuite Invoice is Created or Edited
This is a SuiteScript which auto-applies partially or fully unapplied NetSuite customer payments to open invoices in NetSuite associated with that customer. This script is built to run this operation when an invoice is created or edited, and is still unpaid.