Module: Killbill::Plugin::ActiveMerchant::RSpec
- Includes:
- PropertiesHelper
- Defined in:
- lib/killbill/helpers/active_merchant/killbill_spec_helper.rb
Defined Under Namespace
Classes: FakeClock, FakeJavaPaymentApi, FakeJavaTenantUserApi, FakeJavaUserAccountApi, FakeOSGIKillbillClock
Instance Method Summary collapse
- #build_call_context(tenant_id = '00000011-0022-0033-0044-000000000055') ⇒ Object
- #build_plugin(model, name, conf_dir = '.') ⇒ Object
- #build_pm_properties(account = nil, overrides = {}, set_defaults = true) ⇒ Object
- #create_kb_account(kb_account_id, account_api = @account_api) ⇒ Object
- #create_payment_method(payment_method_model = ::Killbill::Plugin::ActiveMerchant::ActiveRecord::PaymentMethod, kb_account_id = nil, kb_tenant_id = nil, properties = [], options = {}, set_default = true, plugin = @plugin) ⇒ Object
Methods included from PropertiesHelper
#build_property, #find_value_from_properties, #hash_to_properties, #merge_properties, #properties_to_hash
Instance Method Details
#build_call_context(tenant_id = '00000011-0022-0033-0044-000000000055') ⇒ Object
94 95 96 97 98 |
# File 'lib/killbill/helpers/active_merchant/killbill_spec_helper.rb', line 94 def build_call_context(tenant_id = '00000011-0022-0033-0044-000000000055') call_context = ::Killbill::Plugin::Model::CallContext.new call_context.tenant_id = tenant_id call_context.to_ruby(call_context) end |
#build_plugin(model, name, conf_dir = '.') ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/killbill/helpers/active_merchant/killbill_spec_helper.rb', line 100 def build_plugin(model, name, conf_dir = '.') plugin = model.new svcs = { :account_user_api => ::Killbill::Plugin::ActiveMerchant::RSpec::FakeJavaUserAccountApi.new, :payment_api => ::Killbill::Plugin::ActiveMerchant::RSpec::FakeJavaPaymentApi.new, :tenant_user_api => ::Killbill::Plugin::ActiveMerchant::RSpec::FakeJavaTenantUserApi.new } plugin.kb_apis = ::Killbill::Plugin::KillbillApi.new(name, svcs) plugin.clock = ::Killbill::Plugin::ActiveMerchant::RSpec::FakeOSGIKillbillClock.new plugin.logger = ::Logger.new(STDOUT) plugin.logger.level = ::Logger::INFO plugin.conf_dir = File.(conf_dir) plugin.root = "/foo/killbill-#{name}/0.0.1" plugin end |
#build_pm_properties(account = nil, overrides = {}, set_defaults = true) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/killbill/helpers/active_merchant/killbill_spec_helper.rb', line 38 def build_pm_properties(account = nil, overrides = {}, set_defaults = true) cc_number = (overrides.delete(:cc_number) || (set_defaults ? '4242424242424242' : nil)) cc_first_name = (overrides.delete(:cc_first_name) || (set_defaults ? 'John' : nil)) cc_last_name = (overrides.delete(:cc_last_name) || (set_defaults ? 'Doe' : nil)) cc_type = (overrides.delete(:cc_type) || (set_defaults ? 'Visa' : nil)) cc_exp_month = (overrides.delete(:cc_exp_month) || (set_defaults ? 12 : nil)) cc_exp_year = (overrides.delete(:cc_exp_year) || (set_defaults ? 2020 : nil)) cc_last_4 = (overrides.delete(:cc_last_4) || (set_defaults ? 4242 : nil)) address1 = (overrides.delete(:address1) || (set_defaults ? '5, oakriu road' : nil)) address2 = (overrides.delete(:address2) || (set_defaults ? 'apt. 298' : nil)) city = (overrides.delete(:city) || (set_defaults ? 'Gdio Foia' : nil)) state = (overrides.delete(:state) || (set_defaults ? 'FL' : nil)) zip = (overrides.delete(:zip) || (set_defaults ? 49302 : nil)) country = (overrides.delete(:country) || (set_defaults ? 'US' : nil)) cc_verification_value = (overrides.delete(:cc_verification_value) || (set_defaults ? 1234 : nil)) properties = [] properties << build_property('ccNumber', cc_number) properties << build_property('ccFirstName', cc_first_name) properties << build_property('ccLastName', cc_last_name) properties << build_property('ccType', cc_type) properties << build_property('ccExpirationMonth', cc_exp_month) properties << build_property('ccExpirationYear', cc_exp_year) properties << build_property('ccLast4', cc_last_4) properties << build_property('email', account.nil? ? Time.now.to_i.to_s + '[email protected]' : account.email) # Required by e.g. CyberSource properties << build_property('address1', address1) properties << build_property('address2', address2) properties << build_property('city', city) properties << build_property('state', state) properties << build_property('zip', zip) properties << build_property('country', country) properties << build_property('ccVerificationValue', cc_verification_value) overrides.each do |key, value| properties << build_property(key, value) end properties end |
#create_kb_account(kb_account_id, account_api = @account_api) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/killbill/helpers/active_merchant/killbill_spec_helper.rb', line 78 def create_kb_account(kb_account_id, account_api = @account_api) external_key = Time.now.to_i.to_s + '-test' email = external_key + '@tester.com' account = ::Killbill::Plugin::Model::Account.new account.id = kb_account_id account.external_key = external_key account.email = email account.name = 'Integration spec' account.currency = :USD account_api.accounts << account return external_key, kb_account_id end |
#create_payment_method(payment_method_model = ::Killbill::Plugin::ActiveMerchant::ActiveRecord::PaymentMethod, kb_account_id = nil, kb_tenant_id = nil, properties = [], options = {}, set_default = true, plugin = @plugin) ⇒ Object
7 8 9 10 11 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 |
# File 'lib/killbill/helpers/active_merchant/killbill_spec_helper.rb', line 7 def create_payment_method(payment_method_model=::Killbill::Plugin::ActiveMerchant::ActiveRecord::PaymentMethod, kb_account_id=nil, kb_tenant_id=nil, properties = [], = {}, set_default = true, plugin = @plugin) kb_payment_method_id = SecureRandom.uuid if kb_account_id.nil? kb_account_id = SecureRandom.uuid # Create a new account create_kb_account(kb_account_id, plugin.kb_apis.proxied_services[:account_user_api]) end context = plugin.kb_apis.create_context(kb_tenant_id) account = plugin.kb_apis.account_user_api.get_account_by_id(kb_account_id, context) # The rest is pure Ruby context = context.to_ruby(context) # Generate a token pm_properties = build_pm_properties(account, , set_default) info = Killbill::Plugin::Model::PaymentMethodPlugin.new info.properties = pm_properties payment_method = plugin.add_payment_method(kb_account_id, kb_payment_method_id, info, true, properties, context) pm = payment_method_model.from_kb_payment_method_id(kb_payment_method_id, context.tenant_id) pm.should == payment_method pm.kb_account_id.should == kb_account_id pm.kb_payment_method_id.should == kb_payment_method_id pm end |