Class: Braintree::SubscriptionGateway
- Inherits:
-
Object
- Object
- Braintree::SubscriptionGateway
- Defined in:
- lib/braintree/subscription_gateway.rb
Overview
:nodoc:
Class Method Summary (collapse)
-
+ (Object) _add_on_discount_signature
:nodoc:.
-
+ (Object) _create_signature
:nodoc:.
-
+ (Object) _update_signature
:nodoc:.
Instance Method Summary (collapse)
-
- (Object) _do_create(url, params)
:nodoc:.
-
- (Object) _fetch_subscriptions(search, ids)
:nodoc:.
- - (Object) cancel(subscription_id)
- - (Object) create(attributes)
- - (Object) find(id)
-
- (SubscriptionGateway) initialize(gateway)
constructor
A new instance of SubscriptionGateway.
- - (Object) search(&block)
- - (Object) update(subscription_id, attributes)
Constructor Details
- (SubscriptionGateway) initialize(gateway)
A new instance of SubscriptionGateway
3 4 5 6 |
# File 'lib/braintree/subscription_gateway.rb', line 3 def initialize(gateway) @gateway = gateway @config = gateway.config end |
Class Method Details
+ (Object) _add_on_discount_signature
:nodoc:
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/braintree/subscription_gateway.rb', line 90 def self._add_on_discount_signature # :nodoc: [ { :add_ons => [ {:add => [:amount, :inherited_from_id, :never_expires, :number_of_billing_cycles, :quantity]}, {:update => [:amount, :existing_id, :never_expires, :number_of_billing_cycles, :quantity]}, {:remove => [:_any_key_]} ] }, { :discounts => [ {:add => [:amount, :inherited_from_id, :never_expires, :number_of_billing_cycles, :quantity]}, {:update => [:amount, :existing_id, :never_expires, :number_of_billing_cycles, :quantity]}, {:remove => [:_any_key_]} ] } ] end |
+ (Object) _create_signature
:nodoc:
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/braintree/subscription_gateway.rb', line 53 def self._create_signature # :nodoc: [ :billing_day_of_month, :first_billing_date, :id, :merchant_account_id, :never_expires, :number_of_billing_cycles, :payment_method_token, :plan_id, :price, :trial_duration, :trial_duration_unit, :trial_period, {:options => [:do_not_inherit_add_ons_or_discounts, :start_immediately]}, {:descriptor => [:name, :phone]} ] + _add_on_discount_signature end |
+ (Object) _update_signature
:nodoc:
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/braintree/subscription_gateway.rb', line 72 def self._update_signature # :nodoc: [ :id, :merchant_account_id, :never_expires, :number_of_billing_cycles, :payment_method_token, :plan_id, :price, {:options => [ :prorate_charges, :replace_all_add_ons_and_discounts, :revert_subscription_on_proration_failure ]}, {:descriptor => [:name, :phone]} ] + _add_on_discount_signature end |
Instance Method Details
- (Object) _do_create(url, params)
:nodoc:
109 110 111 112 113 114 115 116 117 118 |
# File 'lib/braintree/subscription_gateway.rb', line 109 def _do_create(url, params) # :nodoc: response = @config.http.post url, params if response[:subscription] SuccessfulResult.new(:subscription => Subscription._new(@gateway, response[:subscription])) elsif response[:api_error_response] ErrorResult.new(@gateway, response[:api_error_response]) else raise UnexpectedError, "expected :subscription or :api_error_response" end end |
- (Object) _fetch_subscriptions(search, ids)
:nodoc:
120 121 122 123 124 125 |
# File 'lib/braintree/subscription_gateway.rb', line 120 def _fetch_subscriptions(search, ids) # :nodoc: search.ids.in ids response = @config.http.post "/subscriptions/advanced_search", {:search => search.to_hash} attributes = response[:subscriptions] Util.extract_attribute_as_array(attributes, :subscription).map { |attrs| Subscription._new(@gateway, attrs) } end |
- (Object) cancel(subscription_id)
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/braintree/subscription_gateway.rb', line 8 def cancel(subscription_id) response = @config.http.put "/subscriptions/#{subscription_id}/cancel" if response[:subscription] SuccessfulResult.new(:subscription => Subscription._new(@gateway, response[:subscription])) elsif response[:api_error_response] ErrorResult.new(@gateway, response[:api_error_response]) else raise UnexpectedError, "expected :subscription or :api_error_response" end rescue NotFoundError raise NotFoundError, "subscription with id #{subscription_id.inspect} not found" end |
- (Object) create(attributes)
21 22 23 24 |
# File 'lib/braintree/subscription_gateway.rb', line 21 def create(attributes) Util.verify_keys(SubscriptionGateway._create_signature, attributes) _do_create "/subscriptions", :subscription => attributes end |
- (Object) find(id)
26 27 28 29 30 31 |
# File 'lib/braintree/subscription_gateway.rb', line 26 def find(id) response = @config.http.get "/subscriptions/#{id}" Subscription._new(@gateway, response[:subscription]) rescue NotFoundError raise NotFoundError, "subscription with id #{id.inspect} not found" end |
- (Object) search(&block)
33 34 35 36 37 38 39 |
# File 'lib/braintree/subscription_gateway.rb', line 33 def search(&block) search = SubscriptionSearch.new block.call(search) if block response = @config.http.post "/subscriptions/advanced_search_ids", {:search => search.to_hash} ResourceCollection.new(response) { |ids| _fetch_subscriptions(search, ids) } end |
- (Object) update(subscription_id, attributes)
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/braintree/subscription_gateway.rb', line 41 def update(subscription_id, attributes) Util.verify_keys(SubscriptionGateway._update_signature, attributes) response = @config.http.put "/subscriptions/#{subscription_id}", :subscription => attributes if response[:subscription] SuccessfulResult.new(:subscription => Subscription._new(@gateway, response[:subscription])) elsif response[:api_error_response] ErrorResult.new(@gateway, response[:api_error_response]) else raise UnexpectedError, "expected :subscription or :api_error_response" end end |