Create a gist now

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 http://SuiteSync.io
# Michael Bianco <mike@suitesync.io>
require 'stripe'
Stripe.api_key = 'sk_test_xxx'
customer = Stripe::Customer.create({
:description => "Sample customer for dispute test",
:email => "dispute-#{Time.now.to_i}@example.com",
})
card_token = Stripe::Token.create(
:card => {
# this CC number triggers a dispute
# https://stripe.com/docs/testing#how-do-i-test-disputes
:number => '4000000000000259',
:exp_month => 8,
:exp_year => (Date.today>>24).year,
:cvc => "314"
}
)
customer.sources.create(card: card_token.id)
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
charge.refresh
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
invoice.refresh
if internal_id = invoice.metadata['netsuite_customer_refund_id']
puts "CustomerRefund Internal ID: #{internal_id}"
exit(0)
end
puts "Waiting for CustomerRefund 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