Skip to content

Instantly share code, notes, and snippets.

@iloveitaly
Last active December 4, 2018 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iloveitaly/7832d151e54df77b27dc to your computer and use it in GitHub Desktop.
Save iloveitaly/7832d151e54df77b27dc to your computer and use it in GitHub Desktop.
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