Skip to content

Instantly share code, notes, and snippets.

Embed
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
@santattech
Copy link

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