Skip to content

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..."

This comment has been minimized.

Copy link

@santattech santattech commented Dec 4, 2018

Hi @iloveitaly, in stripe test env, can we create a dispute payment using the card, you used without creating the customer? In my payment flow we are not creating any stripe customer and create a 3d secure source with the card token. After checking whether the created source is chargeable or not, we are making the payment. In this case, when we are using the dispute stripe test card, the stripe charge got succeeded. But no dispute is created.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment