Class: Killbill::Stripe::PrivatePaymentPlugin

Inherits:
Plugin::ActiveMerchant::PrivatePaymentPlugin
  • Object
show all
Defined in:
lib/stripe/private_api.rb

Instance Method Summary collapse

Constructor Details

#initialize(session = {}) ⇒ PrivatePaymentPlugin

Returns a new instance of PrivatePaymentPlugin.



4
5
6
7
8
9
10
# File 'lib/stripe/private_api.rb', line 4

def initialize(session = {})
  super(:stripe,
        ::Killbill::Stripe::StripePaymentMethod,
        ::Killbill::Stripe::StripeTransaction,
        ::Killbill::Stripe::StripeResponse,
        session)
end

Instance Method Details

#add_payment_method(params, options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/stripe/private_api.rb', line 12

def add_payment_method(params, options = {})
  # We need to log-in manually because the call comes unauthenticated from the browser
  # (the default credentials hardcoded: good enough since this should only be used for testing)
  kb_apis.security_api.('admin', 'password')

   = params['kbAccountId']
  kb_tenant_id = params['kbTenantId']

  context = kb_apis.create_context(kb_tenant_id)
   = kb_apis..(, context)

  payment_method_info = ::Killbill::Plugin::Model::PaymentMethodPlugin.new
  payment_method_info.properties = []
  payment_method_info.properties << build_property('cc_first_name', params['stripeCardName'])
  payment_method_info.properties << build_property('address1', params['stripeCardAddressLine1'])
  payment_method_info.properties << build_property('address2', params['stripeCardAddressLine2'])
  payment_method_info.properties << build_property('city', params['stripeCardAddressCity'])
  payment_method_info.properties << build_property('zip', params['stripeCardAddressZip'])
  payment_method_info.properties << build_property('state', params['stripeCardAddressState'])
  payment_method_info.properties << build_property('country', params['stripeCardAddressCountry'])
  payment_method_info.properties << build_property('cc_expiration_month', params['stripeCardExpMonth'])
  payment_method_info.properties << build_property('cc_expiration_year', params['stripeCardExpYear'])
  payment_method_info.properties << build_property('token', params['stripeToken'])

  kb_apis.payment_api.add_payment_method(, params['stripeToken'], 'killbill-stripe', true, payment_method_info, [], context)
end

#create_managed_account(kb_account_id, kb_tenant_id, account = {}, options = {}) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/stripe/private_api.rb', line 50

def (, kb_tenant_id,  = {}, options = {})
   = options[:payment_processor_account_id] || :default
  gateway = gateway(, kb_tenant_id)
  stripe_response = gateway.(, options)
  save_response_and_transaction(stripe_response, :create_managed_account, , kb_tenant_id, )

  stripe_response
end

#get_balance(kb_account_id = nil, kb_tenant_id = nil, options = {}) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/stripe/private_api.rb', line 39

def get_balance( = nil, kb_tenant_id = nil, options = {})
  options[:stripe_account] ||= ::Killbill::Stripe::StripeResponse.(, kb_tenant_id)

   = options[:payment_processor_account_id] || :default
  gateway = gateway(, kb_tenant_id)
  stripe_response = gateway.get_balance(options)
  save_response_and_transaction(stripe_response, :get_balance, , kb_tenant_id, )

  stripe_response
end