Skip to content

Commit

Permalink
Add custom methods and tests for all
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-stripe committed Apr 2, 2019
1 parent 9883454 commit f063abb
Show file tree
Hide file tree
Showing 16 changed files with 161 additions and 31 deletions.
3 changes: 3 additions & 0 deletions lib/stripe/issuing/authorization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ class Authorization < Stripe::APIResource

OBJECT_NAME = "issuing.authorization".freeze

custom_method :approve, http_verb: :post
custom_method :decline, http_verb: :post

def approve(params = {}, opts = {})
resp, opts = request(:post, resource_url + "/approve", params, opts)
initialize_from(resp.data, opts)
Expand Down
2 changes: 2 additions & 0 deletions lib/stripe/issuing/card.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class Card < Stripe::APIResource

OBJECT_NAME = "issuing.card".freeze

custom_method :details, http_verb: :get

def details(params = {}, opts = {})
resp, opts = request(:get, resource_url + "/details", params, opts)
Util.convert_to_stripe_object(resp.data, opts)
Expand Down
2 changes: 1 addition & 1 deletion lib/stripe/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Order < APIResource
OBJECT_NAME = "order".freeze

custom_method :pay, http_verb: :post
custom_method :return_order, http_verb: :post
custom_method :return_order, http_verb: :post, http_path: "returns"

def pay(params, opts = {})
resp, opts = request(:post, pay_url, params, opts)
Expand Down
2 changes: 0 additions & 2 deletions lib/stripe/subscription_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ class SubscriptionItem < APIResource

OBJECT_NAME = "subscription_item".freeze

custom_method :usage_record_summaries, http_verb: :get

def usage_record_summaries(params = {}, opts = {})
resp, opts = request(:get, resource_url + "/usage_record_summaries", params, Util.normalize_opts(opts))
Util.convert_to_stripe_object(resp.data, opts)
Expand Down
1 change: 0 additions & 1 deletion lib/stripe/subscription_schedule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class SubscriptionSchedule < APIResource

custom_method :cancel, http_verb: :post
custom_method :release, http_verb: :post
custom_method :revisions, http_verb: :get

nested_resource_class_methods :revision,
operations: %i[retrieve list]
Expand Down
11 changes: 11 additions & 0 deletions test/stripe/charge_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ class ChargeTest < Test::Unit::TestCase
assert charge.is_a?(Stripe::Charge)
end

context "#capture" do
should "capture the charge" do
charge = Stripe::Charge.retrieve("ch_123")
charge = charge.capture(amount: 100)
assert_requested :post,
"#{Stripe.api_base}/v1/charges/ch_123/capture",
body: { amount: 100 }
assert charge.is_a?(Stripe::Charge)
end
end

context ".capture" do
should "capture the charge" do
charge = Stripe::Charge.capture("ch_123", amount: 100)
Expand Down
9 changes: 9 additions & 0 deletions test/stripe/dispute_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ class DisputeTest < Test::Unit::TestCase
dispute.close
assert_requested :post,
"#{Stripe.api_base}/v1/disputes/#{dispute.id}/close"
assert dispute.is_a?(Stripe::Dispute)
end
end

context ".close" do
should "close a dispute" do
dispute = Stripe::Dispute.close("dp_123")
assert_requested :post, "#{Stripe.api_base}/v1/disputes/dp_123/close"
assert dispute.is_a?(Stripe::Dispute)
end
end
end
Expand Down
42 changes: 32 additions & 10 deletions test/stripe/issuing/authorization_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,40 @@ class AuthorizationTest < Test::Unit::TestCase
assert authorization.is_a?(Stripe::Issuing::Authorization)
end

should "be approveable" do
authorization = Stripe::Issuing::Authorization.retrieve("iauth_123")
authorization.approve
assert_requested :post, "#{Stripe.api_base}/v1/issuing/authorizations/iauth_123/approve"
assert authorization.is_a?(Stripe::Issuing::Authorization)
context ".approve" do
should "approve an authorization" do
payment_intent = Stripe::Issuing::Authorization.approve("iauth_123")

assert_requested :post, "#{Stripe.api_base}/v1/issuing/authorizations/iauth_123/approve"
assert payment_intent.is_a?(Stripe::Issuing::Authorization)
end
end

should "be declineable" do
authorization = Stripe::Issuing::Authorization.retrieve("iauth_123")
authorization.decline
assert_requested :post, "#{Stripe.api_base}/v1/issuing/authorizations/iauth_123/decline"
assert authorization.is_a?(Stripe::Issuing::Authorization)
context "#approve" do
should "approve an authorization" do
authorization = Stripe::Issuing::Authorization.retrieve("iauth_123")
authorization.approve
assert_requested :post, "#{Stripe.api_base}/v1/issuing/authorizations/iauth_123/approve"
assert authorization.is_a?(Stripe::Issuing::Authorization)
end
end

context ".decline" do
should "decline an authorization" do
payment_intent = Stripe::Issuing::Authorization.decline("iauth_123")

assert_requested :post, "#{Stripe.api_base}/v1/issuing/authorizations/iauth_123/decline"
assert payment_intent.is_a?(Stripe::Issuing::Authorization)
end
end

context "#decline" do
should "decline an authorization" do
authorization = Stripe::Issuing::Authorization.retrieve("iauth_123")
authorization.decline
assert_requested :post, "#{Stripe.api_base}/v1/issuing/authorizations/iauth_123/decline"
assert authorization.is_a?(Stripe::Issuing::Authorization)
end
end
end
end
Expand Down
19 changes: 14 additions & 5 deletions test/stripe/issuing/card_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,21 @@ class CardTest < Test::Unit::TestCase
assert card.is_a?(Stripe::Issuing::Card)
end

should "be able to retrieve card details" do
card = Stripe::Issuing::Card.retrieve("ic_123")
context "#details" do
should "retrieve a card's details" do
card_details = Stripe::Issuing::Card.details("ic_123")
assert_requested :get, "#{Stripe.api_base}/v1/issuing/cards/ic_123/details"
assert card_details.is_a?(Stripe::Issuing::CardDetails)
end
end

card_details = card.details
assert_requested :get, "#{Stripe.api_base}/v1/issuing/cards/ic_123/details"
assert card_details.is_a?(Stripe::Issuing::CardDetails)
context ".details" do
should "retrieve a card's details" do
card = Stripe::Issuing::Card.retrieve("ic_123")
card_details = card.details
assert_requested :get, "#{Stripe.api_base}/v1/issuing/cards/ic_123/details"
assert card_details.is_a?(Stripe::Issuing::CardDetails)
end
end
end
end
Expand Down
22 changes: 20 additions & 2 deletions test/stripe/order_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,33 @@ class OrderTest < Test::Unit::TestCase
should "pay an order" do
order = Stripe::Order.retrieve("or_123")
order = order.pay(source: "tok_123")
assert_requested :post, "#{Stripe.api_base}/v1/orders/#{order.id}/pay"
assert order.is_a?(Stripe::Order)
end
end

context ".pay" do
should "pay an order" do
order = Stripe::Order.pay("or_123", source: "tok_123")
assert_requested :post, "#{Stripe.api_base}/v1/orders/or_123/pay"
assert order.is_a?(Stripe::Order)
end
end

context "#return_order" do
should "return an order" do
order = Stripe::Order.retrieve("or_123")
order = order.return_order({})
assert order.is_a?(Stripe::OrderReturn)
order_return = order.return_order({})
assert_requested :post, "#{Stripe.api_base}/v1/orders/#{order.id}/returns"
assert order_return.is_a?(Stripe::OrderReturn)
end
end

context ".return_order" do
should "return an order" do
order_return = Stripe::Order.return_order("or_123")
assert_requested :post, "#{Stripe.api_base}/v1/orders/or_123/returns"
assert order_return.is_a?(Stripe::OrderReturn)
end
end
end
Expand Down
27 changes: 27 additions & 0 deletions test/stripe/payment_intent_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ class PaymentIntentTest < Test::Unit::TestCase
end
end

context ".cancel" do
should "cancel a payment_intent" do
payment_intent = Stripe::PaymentIntent.cancel("pi_123")

assert_requested :post, "#{Stripe.api_base}/v1/payment_intents/pi_123/cancel"
assert payment_intent.is_a?(Stripe::PaymentIntent)
end
end

context "#capture" do
should "capture a payment_intent" do
payment_intent = Stripe::PaymentIntent.construct_from(id: "pi_123", object: "payment_intent")
Expand All @@ -65,6 +74,15 @@ class PaymentIntentTest < Test::Unit::TestCase
end
end

context ".capture" do
should "capture a payment_intent" do
payment_intent = Stripe::PaymentIntent.capture("pi_123", amount_to_capture: 1234)

assert_requested :post, "#{Stripe.api_base}/v1/payment_intents/pi_123/capture"
assert payment_intent.is_a?(Stripe::PaymentIntent)
end
end

context "#confirm" do
should "confirm a payment_intent" do
payment_intent = Stripe::PaymentIntent.construct_from(id: "pi_123", object: "payment_intent")
Expand All @@ -76,5 +94,14 @@ class PaymentIntentTest < Test::Unit::TestCase
assert payment_intent.is_a?(Stripe::PaymentIntent)
end
end

context ".confirm" do
should "confirm a payment_intent" do
payment_intent = Stripe::PaymentIntent.confirm("pi_123", source: "src_123")

assert_requested :post, "#{Stripe.api_base}/v1/payment_intents/pi_123/confirm"
assert payment_intent.is_a?(Stripe::PaymentIntent)
end
end
end
end
18 changes: 18 additions & 0 deletions test/stripe/payment_method_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ class PaymentMethodTest < Test::Unit::TestCase
end
end

context ".attach" do
should "attach payment_method" do
payment_method = Stripe::PaymentMethod.attach("pm_123", customer: "cus_123")

assert_requested :post, "#{Stripe.api_base}/v1/payment_methods/pm_123/attach"
assert payment_method.is_a?(Stripe::PaymentMethod)
end
end

context "#detach" do
should "detach payment_method" do
payment_method = Stripe::PaymentMethod.construct_from(id: "pm_123", object: "payment_method")
Expand All @@ -62,5 +71,14 @@ class PaymentMethodTest < Test::Unit::TestCase
assert payment_method.is_a?(Stripe::PaymentMethod)
end
end

context ".detach" do
should "detach payment_method" do
payment_method = Stripe::PaymentMethod.detach("pm_123")

assert_requested :post, "#{Stripe.api_base}/v1/payment_methods/pm_123/detach"
assert payment_method.is_a?(Stripe::PaymentMethod)
end
end
end
end
7 changes: 7 additions & 0 deletions test/stripe/payout_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,12 @@ class PayoutTest < Test::Unit::TestCase
assert payout.is_a?(Stripe::Payout)
end
end

context ".cancel" do
should "cancel a payout" do
payout = Stripe::Payout.cancel("pm_123")
assert payout.is_a?(Stripe::Payout)
end
end
end
end
10 changes: 0 additions & 10 deletions test/stripe/subscription_schedule_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,6 @@ class SubscriptionScheduleTest < Test::Unit::TestCase
should "retrieve the subscription schedule's revisions" do
schedule = Stripe::SubscriptionSchedule.retrieve("sub_sched_123")
revisions = schedule.revisions
assert_requested :get,
"#{Stripe.api_base}/v1/subscription_schedules/#{schedule.id}/revisions"
assert revisions.data.is_a?(Array)
assert revisions.data[0].is_a?(Stripe::SubscriptionScheduleRevision)
end
end

context ".revisions" do
should "retrieve the subscription schedule's revisions" do
revisions = Stripe::SubscriptionSchedule.revisions("sub_sched_123")
assert_requested :get,
"#{Stripe.api_base}/v1/subscription_schedules/sub_sched_123/revisions"
assert revisions.data.is_a?(Array)
Expand Down
9 changes: 9 additions & 0 deletions test/stripe/subscription_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,17 @@ class SubscriptionTest < Test::Unit::TestCase
should "be able to delete a subscriptions's discount" do
subscription = Stripe::Subscription.retrieve("sub_123")
subscription = subscription.delete_discount
assert_requested :delete, "#{Stripe.api_base}/v1/subscriptions/sub_123/discount"
assert subscription.is_a?(Stripe::Subscription)
end
end

context ".delete_discount" do
should "be able to delete a subscriptions's discount" do
discount = Stripe::Subscription.delete_discount("sub_123")
assert_requested :delete, "#{Stripe.api_base}/v1/subscriptions/sub_123/discount"
assert discount.is_a?(Stripe::Discount)
end
end
end
end
8 changes: 8 additions & 0 deletions test/stripe/topup_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,13 @@ class TopupTest < Test::Unit::TestCase
assert topup.is_a?(Stripe::Topup)
end
end

context ".cancel" do
should "cancel the topup" do
topup = Stripe::Topup.cancel("tu_123")
assert_requested :post, "#{Stripe.api_base}/v1/topups/tu_123/cancel"
assert topup.is_a?(Stripe::Topup)
end
end
end
end

0 comments on commit f063abb

Please sign in to comment.