Skip to content

Instantly share code, notes, and snippets.

@iloveitaly
Last active May 30, 2016 13:16
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/65c6a9dd955629bcb355 to your computer and use it in GitHub Desktop.
Save iloveitaly/65c6a9dd955629bcb355 to your computer and use it in GitHub Desktop.
Example of creating a SalesOrder in NetSuite by creating a Stripe Order using http://SuiteSync.io/
# Michael Bianco <mike@suitesync.io>
require 'stripe'
Stripe.api_key = 'sk_test_123'
customer = Stripe::Customer.create(
:description => "Sample customer for NetSuite",
:email => "sample@example.com",
)
card_token = Stripe::Token.create(
:card => {
:number => 4242424242424242,
:exp_month => 8,
:exp_year => (Date.today>>24).year,
:cvc => "314"
}
)
customer.sources.create(card: card_token.id)
# 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 => 'Jenny Rosen',
:address => {
:line1 => '1234 Main street',
:line2 => 'Top Floor',
:city => 'Anytown',
:country => 'US',
:postal_code => '123456'
}
},
:customer => customer.id
)
order.pay(customer: customer)
# retrieve the internalId of the created CustomerPayment
# NOTE this will only work if your integration account is processing live translations
loop do
order.refresh
if internal_id = order.metadata['netsuite_sales_order_id']
puts "SalesOrder Internal ID: #{internal_id}"
exit(0)
end
puts "Waiting for Order to translate to NetSuite..."
sleep(1)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment