Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example of how to create a NetSuite SalesOrder (or Invoice) with an associated payment using the Stripe Relay API with http://SuiteSync.io/
# Michael Bianco <mike@suitesync.io>
# Description: Example of how to create a NetSuite SalesOrder (or Invoice) with an
# associated payment using the Stripe Relay API
# Usage:
# gem install stripe
# export STRIPE_KEY=sk_test_
# ruby stripe_simple_netsuite_ecommerce_with_relay.rb
require 'stripe'
Stripe.api_key = ENV['STRIPE_KEY']
customer = Stripe::Customer.create(
description: "Sample customer for NetSuite",
email: "sample@example.com",
)
customer.sources.create(card: 'tok_visa')
# ensures that a new product and sku is created
randomization_token = Time.now.to_i
product = Stripe::Product.create(
:name => 'Your Product',
:description => 'A description',
:id => "your_product_id_#{randomization_token}",
# `shippable = true` creates a InventoryItem instead of a NonInventoryItem
:shippable => false
)
sku = Stripe::SKU.create(
:id => "your_product_sku_#{randomization_token}",
:product => product.id,
:price => 15_00,
:currency => 'usd',
:inventory => {
'type' => 'infinite'
}
)
order = Stripe::Order.create(
:currency => 'usd',
:items => [
{
:type => 'sku',
:parent => sku.id
}
],
:shipping => {
:name => 'John Doe',
:address => {
:line1 => '1234 Main street',
:line2 => 'Top Floor',
:city => 'Anytown',
:country => 'US',
:postal_code => '123456'
}
},
:customer => customer.id
)
order.pay(customer: customer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment