Class: FakeBraintree::Subscription
- Inherits:
-
Object
- Object
- FakeBraintree::Subscription
show all
- Includes:
- Helpers
- Defined in:
- lib/fake_braintree/subscription.rb
Instance Method Summary
collapse
Methods included from Helpers
#create_id, #gzip, #gzipped_response, #md5
Constructor Details
#initialize(subscription_hash_from_params, options) ⇒ Subscription
Returns a new instance of Subscription.
7
8
9
10
11
12
13
14
15
|
# File 'lib/fake_braintree/subscription.rb', line 7
def initialize(subscription_hash_from_params, options)
id = subscription_hash_from_params['id'] || options[:id]
@subscription_hash = subscription_hash_from_params.merge(
'merchant_id' => options[:merchant_id],
'id' => id
)
set_subscription_id
set_subscription_status
end
|
Instance Method Details
#cancel ⇒ Object
35
36
37
38
39
40
41
42
|
# File 'lib/fake_braintree/subscription.rb', line 35
def cancel
if subscription_exists_in_registry?
canceled_subscription = update_existing_subscription('status' => canceled_status)
response_for_canceled_subscription(canceled_subscription)
else
response_for_subscription_not_found
end
end
|
#create ⇒ Object
17
18
19
20
21
22
23
24
|
# File 'lib/fake_braintree/subscription.rb', line 17
def create
create_subscription_with(subscription_hash)
if credit_card = FakeBraintree.registry.credit_cards[payment_method_token]
credit_card['subscriptions'] ||= []
credit_card['subscriptions'] << subscription_hash
end
response_for_created_subscription(subscription_hash)
end
|
#update ⇒ Object
26
27
28
29
30
31
32
33
|
# File 'lib/fake_braintree/subscription.rb', line 26
def update
if subscription_exists_in_registry?
updated_subscription = update_existing_subscription(subscription_hash)
response_for_created_subscription(updated_subscription)
else
response_for_subscription_not_found
end
end
|