forked from stripe-ruby-mock/stripe-ruby-mock
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix subscription examples when running specs in live mode
* Stripe returns an instance of `Stripe::Discount` and not a basic `Stripe::StripeObject` * Additionally while here update the add_coupon helper to allow it to add discount/coupon to other types of objects besides customers and ensure that we are returning an instance of `Stripe::Discount` with correct parameters in all cases where we would expect Stripe to do so.
- Loading branch information
Showing
4 changed files
with
18 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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
21 changes: 10 additions & 11 deletions
21
lib/stripe_mock/request_handlers/helpers/coupon_helpers.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
module StripeMock | ||
module RequestHandlers | ||
module Helpers | ||
def add_coupon_to_object(object, coupon) | ||
discount_attrs = {}.tap do |attrs| | ||
attrs[object[:object]] = object[:id] | ||
attrs[:coupon] = coupon | ||
attrs[:start] = Time.now.to_i | ||
attrs[:end] = (DateTime.now >> coupon[:duration_in_months].to_i).to_time.to_i if coupon[:duration] == 'repeating' | ||
end | ||
|
||
def add_coupon_to_customer(customer, coupon) | ||
customer[:discount] = { | ||
coupon: coupon, | ||
customer: customer[:id], | ||
start: Time.now.to_i, | ||
} | ||
customer[:discount][:end] = (DateTime.now >> coupon[:duration_in_months]).to_time.to_i if coupon[:duration].to_sym == :repeating && coupon[:duration_in_months] | ||
|
||
customer | ||
object[:discount] = Stripe::Discount.construct_from(discount_attrs) | ||
object | ||
end | ||
|
||
end | ||
end | ||
end | ||
end |
This file contains 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
This file contains 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