Created
February 4, 2015 01:25
-
-
Save jonskirk/a11749b358833ec4234b to your computer and use it in GitHub Desktop.
Stripe service problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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