Created
October 30, 2017 14:09
-
-
Save iloveitaly/b9f3bcb4be5924c6935f0cc0b9533513 to your computer and use it in GitHub Desktop.
Example of how to create a NetSuite SalesOrder (or Invoice) with an associated payment using the Stripe Relay API with 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
# 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
got this in JS?