Skip to content

Instantly share code, notes, and snippets.

@jonskirk
Created February 4, 2015 01:25
Show Gist options
  • Save jonskirk/a11749b358833ec4234b to your computer and use it in GitHub Desktop.
Save jonskirk/a11749b358833ec4234b to your computer and use it in GitHub Desktop.
Stripe service problem
class CreateProduct
def self.call(options={})
product = Product.new(options)
if !product.valid?
return product
end
begin
Stripe::Product.create(
id: options[:stripe_id],
amount: options[:amount],
currency: 'usd',
interval: options[:interval],
name: options[:name],
)
rescue Stripe::StripeError => e
product.errors[:base] << e.message
return product
end
product.save
return product
end
end
require 'test_helper'
class StripeTest < ActionDispatch::IntegrationTest
test "should create a test product" do
product = CreateProduct.call(stripe_id: 'test_plan', name: 'Test Daily Plan',
price: 500, interval: 'day', description: 'Test daily plan for debugging purposes')
assert product
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment