Class: Killbill::BraintreeBlue::PaymentPlugin

Inherits:
Plugin::ActiveMerchant::PaymentPlugin
  • Object
show all
Defined in:
lib/braintree_blue/api.rb

Instance Method Summary collapse

Constructor Details

#initializePaymentPlugin

Returns a new instance of PaymentPlugin.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/braintree_blue/api.rb', line 5

def initialize
  gateway_builder = Proc.new do |config|
    ::ActiveMerchant::Billing::BraintreeBlueGateway.application_id = config[:channel] || 'killbill_SP'
    ::ActiveMerchant::Billing::BraintreeBlueGateway.new :merchant_id => config[:merchant_id],
                                                        :public_key  => config[:public_key],
                                                        :private_key => config[:private_key]
  end

  super(gateway_builder,
        :braintree_blue,
        ::Killbill::BraintreeBlue::BraintreeBluePaymentMethod,
        ::Killbill::BraintreeBlue::BraintreeBlueTransaction,
        ::Killbill::BraintreeBlue::BraintreeBlueResponse)
end

Instance Method Details

#add_payment_method(kb_account_id, kb_payment_method_id, payment_method_props, set_default, properties, context) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/braintree_blue/api.rb', line 96

def add_payment_method(, kb_payment_method_id, payment_method_props, set_default, properties, context)
  braintree_customer_id = find_value_from_properties(payment_method_props.properties, :customer) ||
    BraintreeBluePaymentMethod.(, context.tenant_id)

  options = {
    :payment_method_nonce => find_value_from_properties(payment_method_props.properties, :payment_method_nonce),
    :customer => braintree_customer_id,
    :company => 
  }

  if ::Killbill::Plugin::ActiveMerchant::Utils.normalized(options, :skip_gw)
    # See https://github.com/killbill/killbill-braintree-blue-plugin/pull/4
    options[:token] = find_value_from_properties(payment_method_props.properties, :token)
  elsif find_value_from_properties(payment_method_props.properties, :cc_number).blank? &&
       !find_value_from_properties(payment_method_props.properties, :token).blank?
    pm_props_hsh = properties_to_hash(payment_method_props.properties)

    # Pass 'token' (along with CC details) or 'payment_method_nonce'
    # For convenience, we translate 'token' into 'payment_method_nonce'
    # Note: we remove the token because the Braintree AM implementation always requires a CreditCard object
    options[:payment_method_nonce] = pm_props_hsh.delete(:token)

    payment_method_props = Killbill::Plugin::Model::PaymentMethodPlugin.new
    payment_method_props.properties = hash_to_properties(pm_props_hsh)
  end

  properties = merge_properties(properties, options)
  super(, kb_payment_method_id, payment_method_props, set_default, properties, context)
end

#authorize_payment(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/braintree_blue/api.rb', line 28

def authorize_payment(, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
  options = {
    :payment_method_token => true
  }

  options.merge(get_merchant_id(currency, context.tenant_id))

  properties = merge_properties(properties, options)
  super(, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
end

#build_form_descriptor(kb_account_id, descriptor_fields, properties, context) ⇒ Object



166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/braintree_blue/api.rb', line 166

def build_form_descriptor(, descriptor_fields, properties, context)
  # Pass extra parameters for the gateway here
  options = {}
  properties = merge_properties(properties, options)

  # Add your custom static hidden tags here
  options = {
      #:token => config[:braintree_blue][:token]
  }
  descriptor_fields = merge_properties(descriptor_fields, options)

  super(, descriptor_fields, properties, context)
end

#capture_payment(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/braintree_blue/api.rb', line 39

def capture_payment(, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
  # Pass extra parameters for the gateway here
  options = {}
  options.merge(get_merchant_id(currency, context.tenant_id))
  properties = merge_properties(properties, options)
  super(, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
end

#credit_payment(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/braintree_blue/api.rb', line 63

def credit_payment(, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
  options = {
    :payment_method_token => true
  }
  options.merge(get_merchant_id(currency, context.tenant_id))
  properties = merge_properties(properties, options)
  super(, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
end

#delete_payment_method(kb_account_id, kb_payment_method_id, properties, context) ⇒ Object



126
127
128
129
130
131
132
# File 'lib/braintree_blue/api.rb', line 126

def delete_payment_method(, kb_payment_method_id, properties, context)
  # Pass extra parameters for the gateway here
  options = {}

  properties = merge_properties(properties, options)
  super(, kb_payment_method_id, properties, context)
end

#get_merchant_id(currency, kb_tenant_id = nil) ⇒ Object



194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/braintree_blue/api.rb', line 194

def get_merchant_id(currency, kb_tenant_id=nil)
  config = ::Killbill::Plugin::ActiveMerchant.config(kb_tenant_id)
  options = {}
  if config[:braintree_blue][:multicurrency]
    multicurrency = config[:multicurrency] || {}
    case currency
      when "USD"
        options = {:merchant_account_id => multicurrency[:USD]}
      when "EUR"
        options = {:merchant_account_id => multicurrency[:EUR]}
      when "PLN"
        options = {:merchant_account_id => multicurrency[:PLN]}
    end
  end
  options
end

#get_payment_info(kb_account_id, kb_payment_id, properties, context) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/braintree_blue/api.rb', line 80

def get_payment_info(, kb_payment_id, properties, context)
  # Pass extra parameters for the gateway here
  options = {}

  properties = merge_properties(properties, options)
  super(, kb_payment_id, properties, context)
end

#get_payment_method_detail(kb_account_id, kb_payment_method_id, properties, context) ⇒ Object



134
135
136
137
138
139
140
# File 'lib/braintree_blue/api.rb', line 134

def get_payment_method_detail(, kb_payment_method_id, properties, context)
  # Pass extra parameters for the gateway here
  options = {}

  properties = merge_properties(properties, options)
  super(, kb_payment_method_id, properties, context)
end

#get_payment_methods(kb_account_id, refresh_from_gateway, properties, context) ⇒ Object



146
147
148
149
150
151
152
# File 'lib/braintree_blue/api.rb', line 146

def get_payment_methods(, refresh_from_gateway, properties, context)
  # Pass extra parameters for the gateway here
  options = {}

  properties = merge_properties(properties, options)
  super(, refresh_from_gateway, properties, context)
end

#on_event(event) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/braintree_blue/api.rb', line 20

def on_event(event)
  # Require to deal with per tenant configuration invalidation
  super(event)
  #
  # Custom event logic could be added below...
  #
end

#process_notification(notification, properties, context) ⇒ Object



180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/braintree_blue/api.rb', line 180

def process_notification(notification, properties, context)
  # Pass extra parameters for the gateway here
  options = {}
  properties = merge_properties(properties, options)

  super(notification, properties, context) do |gw_notification, service|
    # Retrieve the payment
    # gw_notification.kb_payment_id =
    #
    # Set the response body
    # gw_notification.entity =
  end
end

#purchase_payment(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context) ⇒ Object



47
48
49
50
51
52
53
54
# File 'lib/braintree_blue/api.rb', line 47

def purchase_payment(, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
  options = {
    :payment_method_token => true
  }
  options.merge(get_merchant_id(currency, context.tenant_id))
  properties = merge_properties(properties, options)
  super(, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
end

#refund_payment(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/braintree_blue/api.rb', line 72

def refund_payment(, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
  # Pass extra parameters for the gateway here
  options = {}
  options.merge(get_merchant_id(currency, context.tenant_id))
  properties = merge_properties(properties, options)
  super(, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
end

#reset_payment_methods(kb_account_id, payment_methods, properties, context) ⇒ Object



162
163
164
# File 'lib/braintree_blue/api.rb', line 162

def reset_payment_methods(, payment_methods, properties, context)
  super
end

#search_payment_methods(search_key, offset, limit, properties, context) ⇒ Object



154
155
156
157
158
159
160
# File 'lib/braintree_blue/api.rb', line 154

def search_payment_methods(search_key, offset, limit, properties, context)
  # Pass extra parameters for the gateway here
  options = {}

  properties = merge_properties(properties, options)
  super(search_key, offset, limit, properties, context)
end

#search_payments(search_key, offset, limit, properties, context) ⇒ Object



88
89
90
91
92
93
94
# File 'lib/braintree_blue/api.rb', line 88

def search_payments(search_key, offset, limit, properties, context)
  # Pass extra parameters for the gateway here
  options = {}
  options.merge(get_merchant_id(currency, context.tenant_id))
  properties = merge_properties(properties, options)
  super(search_key, offset, limit, properties, context)
end

#set_default_payment_method(kb_account_id, kb_payment_method_id, properties, context) ⇒ Object



142
143
144
# File 'lib/braintree_blue/api.rb', line 142

def set_default_payment_method(, kb_payment_method_id, properties, context)
  # TODO
end

#void_payment(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, properties, context) ⇒ Object



56
57
58
59
60
61
# File 'lib/braintree_blue/api.rb', line 56

def void_payment(, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, properties, context)
  # Pass extra parameters for the gateway here
  options = {}
  properties = merge_properties(properties, options)
  super(, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, properties, context)
end