Class: Killbill::Litle::PaymentPlugin
- Inherits:
-
Plugin::ActiveMerchant::PaymentPlugin
- Object
- Plugin::ActiveMerchant::PaymentPlugin
- Killbill::Litle::PaymentPlugin
- Defined in:
- lib/litle/api.rb
Instance Method Summary collapse
- #add_payment_method(kb_account_id, kb_payment_method_id, payment_method_props, set_default, properties, context) ⇒ Object
-
#authorize_payment(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context) ⇒ Object
TODO Should we set the Litle Id field to check for dups (www.litle.com/mc-secure/DupeChecking_V1.2.pdf)?.
- #build_form_descriptor(kb_account_id, descriptor_fields, properties, context) ⇒ Object
- #capture_payment(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context) ⇒ Object
- #credit_payment(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context) ⇒ Object
- #delete_payment_method(kb_account_id, kb_payment_method_id, properties, context) ⇒ Object
- #get_payment_info(kb_account_id, kb_payment_id, properties, context) ⇒ Object
- #get_payment_method_detail(kb_account_id, kb_payment_method_id, properties, context) ⇒ Object
- #get_payment_methods(kb_account_id, refresh_from_gateway, properties, context) ⇒ Object
-
#initialize ⇒ PaymentPlugin
constructor
A new instance of PaymentPlugin.
- #on_event(event) ⇒ Object
- #process_notification(notification, properties, context) ⇒ Object
- #purchase_payment(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context) ⇒ Object
- #refund_payment(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context) ⇒ Object
- #reset_payment_methods(kb_account_id, payment_methods, properties, context) ⇒ Object
- #search_payment_methods(search_key, offset, limit, properties, context) ⇒ Object
- #search_payments(search_key, offset, limit, properties, context) ⇒ Object
- #set_default_payment_method(kb_account_id, kb_payment_method_id, properties, context) ⇒ Object
- #set_payment_processor_account_id(currency, kb_tenant_id = nil) ⇒ Object
- #void_payment(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, properties, context) ⇒ Object
Constructor Details
#initialize ⇒ PaymentPlugin
Returns a new instance of PaymentPlugin.
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/litle/api.rb', line 5 def initialize gateway_builder = Proc.new do |config| ::ActiveMerchant::Billing::LitleGateway.new :login => config[:login], :password => config[:password], :merchant_id => config[:merchant_id] end super(gateway_builder, :litle, ::Killbill::Litle::LitlePaymentMethod, ::Killbill::Litle::LitleTransaction, ::Killbill::Litle::LitleResponse) 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 |
# File 'lib/litle/api.rb', line 96 def add_payment_method(kb_account_id, kb_payment_method_id, payment_method_props, set_default, properties, context) # paypageRegistrationId is passed via properties paypage_registration_id = find_value_from_properties(properties, 'paypageRegistrationId') # paypageRegistrationId is passed from the json body paypage_registration_id = find_value_from_properties(payment_method_props.properties, 'paypageRegistrationId') if paypage_registration_id.nil? # Pass extra parameters for the gateway here = {} # Register the token unless paypage_registration_id.nil? payment_processor_account_id = [:payment_processor_account_id] || :default gateway = lookup_gateway(payment_processor_account_id, context.tenant_id) litle_response = gateway.register_token_request(paypage_registration_id, ) response, _ = save_response_and_transaction(litle_response, :register_token_request, kb_account_id, context.tenant_id, payment_processor_account_id) raise response. unless response.success [:skip_gw] = true [:token] = litle_response. end properties = merge_properties(properties, ) super(kb_account_id, 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
TODO Should we set the Litle Id field to check for dups (www.litle.com/mc-secure/DupeChecking_V1.2.pdf)?
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/litle/api.rb', line 29 def (kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context) # Pass extra parameters for the gateway here = set_payment_processor_account_id(currency, context.tenant_id) paypage_registration_id = find_value_from_properties(properties, 'paypageRegistrationId') [:paypage_registration_id] = paypage_registration_id unless paypage_registration_id.blank? properties = merge_properties(properties, ) super(kb_account_id, 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
161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/litle/api.rb', line 161 def build_form_descriptor(kb_account_id, descriptor_fields, properties, context) # Pass extra parameters for the gateway here = {} properties = merge_properties(properties, ) # Add your custom static hidden tags here = { #:token => config[:litle][:token] } descriptor_fields = merge_properties(descriptor_fields, ) super(kb_account_id, 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
40 41 42 43 44 45 46 |
# File 'lib/litle/api.rb', line 40 def capture_payment(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context) # Pass extra parameters for the gateway here = set_payment_processor_account_id(currency, context.tenant_id) properties = merge_properties(properties, ) super(kb_account_id, 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
64 65 66 67 68 69 70 |
# File 'lib/litle/api.rb', line 64 def credit_payment(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context) # Pass extra parameters for the gateway here = set_payment_processor_account_id(currency, context.tenant_id) properties = merge_properties(properties, ) super(kb_account_id, 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
121 122 123 124 125 126 127 |
# File 'lib/litle/api.rb', line 121 def delete_payment_method(kb_account_id, kb_payment_method_id, properties, context) # Pass extra parameters for the gateway here = {} properties = merge_properties(properties, ) super(kb_account_id, kb_payment_method_id, properties, context) end |
#get_payment_info(kb_account_id, kb_payment_id, properties, context) ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/litle/api.rb', line 80 def get_payment_info(kb_account_id, kb_payment_id, properties, context) # Pass extra parameters for the gateway here = {} properties = merge_properties(properties, ) super(kb_account_id, kb_payment_id, properties, context) end |
#get_payment_method_detail(kb_account_id, kb_payment_method_id, properties, context) ⇒ Object
129 130 131 132 133 134 135 |
# File 'lib/litle/api.rb', line 129 def get_payment_method_detail(kb_account_id, kb_payment_method_id, properties, context) # Pass extra parameters for the gateway here = {} properties = merge_properties(properties, ) super(kb_account_id, kb_payment_method_id, properties, context) end |
#get_payment_methods(kb_account_id, refresh_from_gateway, properties, context) ⇒ Object
141 142 143 144 145 146 147 |
# File 'lib/litle/api.rb', line 141 def get_payment_methods(kb_account_id, refresh_from_gateway, properties, context) # Pass extra parameters for the gateway here = {} properties = merge_properties(properties, ) super(kb_account_id, refresh_from_gateway, properties, context) end |
#on_event(event) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/litle/api.rb', line 19 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
175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/litle/api.rb', line 175 def process_notification(notification, properties, context) # Pass extra parameters for the gateway here = {} properties = merge_properties(properties, ) 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
48 49 50 51 52 53 54 |
# File 'lib/litle/api.rb', line 48 def purchase_payment(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context) # Pass extra parameters for the gateway here = set_payment_processor_account_id(currency, context.tenant_id) properties = merge_properties(properties, ) super(kb_account_id, 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/litle/api.rb', line 72 def refund_payment(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context) # Pass extra parameters for the gateway here = set_payment_processor_account_id(currency, context.tenant_id) properties = merge_properties(properties, ) super(kb_account_id, 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
157 158 159 |
# File 'lib/litle/api.rb', line 157 def reset_payment_methods(kb_account_id, payment_methods, properties, context) super end |
#search_payment_methods(search_key, offset, limit, properties, context) ⇒ Object
149 150 151 152 153 154 155 |
# File 'lib/litle/api.rb', line 149 def search_payment_methods(search_key, offset, limit, properties, context) # Pass extra parameters for the gateway here = {} properties = merge_properties(properties, ) 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/litle/api.rb', line 88 def search_payments(search_key, offset, limit, properties, context) # Pass extra parameters for the gateway here = {} properties = merge_properties(properties, ) super(search_key, offset, limit, properties, context) end |
#set_default_payment_method(kb_account_id, kb_payment_method_id, properties, context) ⇒ Object
137 138 139 |
# File 'lib/litle/api.rb', line 137 def set_default_payment_method(kb_account_id, kb_payment_method_id, properties, context) # TODO end |
#set_payment_processor_account_id(currency, kb_tenant_id = nil) ⇒ Object
189 190 191 192 193 194 195 196 197 198 |
# File 'lib/litle/api.rb', line 189 def set_payment_processor_account_id(currency, kb_tenant_id=nil) config = ::Killbill::Plugin::ActiveMerchant.config(kb_tenant_id) = {} currency_account_id_map = config[:multicurrency] if currency_account_id_map && currency_account_id_map.is_a?(Hash) currency_account_id_map.default = currency_account_id_map.values[0] = {:payment_processor_account_id => currency_account_id_map[currency.to_sym]} end 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 62 |
# File 'lib/litle/api.rb', line 56 def void_payment(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, properties, context) # Pass extra parameters for the gateway here = {} properties = merge_properties(properties, ) super(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, properties, context) end |