Instantly share code, notes, and snippets.

What would you like to do?
Example of creating a dispute (chargeback) in Stripe's test mode and inspecting the resulting CustomerRefund in NetSuite using
# Michael Bianco <>
require 'stripe'
Stripe.api_key = 'sk_test_xxx'
customer = Stripe::Customer.create({
:description => "Sample customer for dispute test",
:email => "dispute-#{}",
card_token = Stripe::Token.create(
:card => {
# this CC number triggers a dispute
:number => '4000000000000259',
:exp_month => 8,
:exp_year => (>>24).year,
:cvc => "314"
charge = Stripe::Charge.create(
:amount => 80_00,
:capture => true,
:currency => "usd",
:customer => customer,
# dispute is created automatically based on CC number specified; refresh to load dispute
dispute = charge.dispute
# retrieve the internalId of the created CustomerRefund
# if an invoice is tied to a disputed charge, a CreditMemo will be created as well
# if you are using the integration on the reconciliation-only flow, disputes will be handled
# as a deposit cash back line item instead of creating a CustomerRefund
# NOTE this will only work if your integration account is processing live translations
loop do
if internal_id = invoice.metadata['netsuite_customer_refund_id']
puts "CustomerRefund Internal ID: #{internal_id}"
puts "Waiting for CustomerRefund to translate to NetSuite..."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment