Class: Killbill::PaypalExpress::PrivatePaymentPlugin
- Inherits:
-
Killbill::Plugin::ActiveMerchant::PrivatePaymentPlugin
- Object
- Killbill::Plugin::ActiveMerchant::PrivatePaymentPlugin
- Killbill::PaypalExpress::PrivatePaymentPlugin
- Defined in:
- lib/paypal_express/private_api.rb
Constant Summary collapse
- ONE_HOUR_AGO =
3600
- STATUS =
{:CAPTURE => {:success_status => 'Completed', :type => 'Payment'}, :AUTHORIZE => {:success_status => 'Pending', :type => 'Authorization'}, :REFUND => {:success_status => 'Completed', :type => 'Refund'}}
Instance Method Summary collapse
- #fix_unknown_transaction(plugin_response, trx_plugin_info, gateway) ⇒ Object
- #get_external_keys_for_accounts(kb_account_ids, kb_tenant_id) ⇒ Object
-
#initialize(session = {}) ⇒ PrivatePaymentPlugin
constructor
A new instance of PrivatePaymentPlugin.
- #initiate_express_checkout(kb_account_id, kb_tenant_id, amount_in_cents = 0, currency = 'USD', with_baid = true, options = {}) ⇒ Object
- #search_transaction(start_time, gateway, kb_payment_transaction_id) ⇒ Object
- #to_express_checkout_url(response, kb_tenant_id = nil, options = {}) ⇒ Object
Constructor Details
#initialize(session = {}) ⇒ PrivatePaymentPlugin
Returns a new instance of PrivatePaymentPlugin.
10 11 12 13 14 15 16 |
# File 'lib/paypal_express/private_api.rb', line 10 def initialize(session = {}) super(:paypal_express, ::Killbill::PaypalExpress::PaypalExpressPaymentMethod, ::Killbill::PaypalExpress::PaypalExpressTransaction, ::Killbill::PaypalExpress::PaypalExpressResponse, session) end |
Instance Method Details
#fix_unknown_transaction(plugin_response, trx_plugin_info, gateway) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/paypal_express/private_api.rb', line 52 def fix_unknown_transaction(plugin_response, trx_plugin_info, gateway) status, transaction_id, type, amount, currency = search_transaction(trx_plugin_info.created_date - ONE_HOUR_AGO, gateway, trx_plugin_info.kb_transaction_payment_id) return false if status.blank? || transaction_id.blank? || type.blank? if type == STATUS[trx_plugin_info.transaction_type][:type] && status == STATUS[trx_plugin_info.transaction_type][:success_status] plugin_response.transition_to_success transaction_id, amount, currency logger.info("Fixed UNDEFINED kb_transaction_id='#{trx_plugin_info.kb_transaction_payment_id}' to PROCESSED") return true end false end |
#get_external_keys_for_accounts(kb_account_ids, kb_tenant_id) ⇒ Object
47 48 49 50 |
# File 'lib/paypal_express/private_api.rb', line 47 def get_external_keys_for_accounts(kb_account_ids, kb_tenant_id) context = kb_apis.create_context(kb_tenant_id) kb_account_ids.map {|id| kb_apis.account_user_api.get_account_by_id(id, context).external_key } end |
#initiate_express_checkout(kb_account_id, kb_tenant_id, amount_in_cents = 0, currency = 'USD', with_baid = true, options = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/paypal_express/private_api.rb', line 19 def initiate_express_checkout(kb_account_id, kb_tenant_id, amount_in_cents=0, currency='USD', with_baid=true, = {}) [:currency] ||= currency # Required arguments [:return_url] ||= 'http://www.example.com/success' [:cancel_return_url] ||= 'http://www.example.com/sad_panda' if with_baid [:billing_agreement] ||= {} [:billing_agreement][:type] ||= 'MerchantInitiatedBilling' [:billing_agreement][:description] ||= 'Kill Bill billing agreement' end # Go to Paypal (SetExpressCheckout call) payment_processor_account_id = [:payment_processor_account_id] || :default paypal_express_response = gateway(payment_processor_account_id, kb_tenant_id).(amount_in_cents, ) response, transaction = save_response_and_transaction(paypal_express_response, :initiate_express_checkout, kb_account_id, kb_tenant_id, payment_processor_account_id) response end |
#search_transaction(start_time, gateway, kb_payment_transaction_id) ⇒ Object
68 69 70 71 72 |
# File 'lib/paypal_express/private_api.rb', line 68 def search_transaction(start_time, gateway, kb_payment_transaction_id) = {:start_date => start_time, :invoice_id => kb_payment_transaction_id} response = gateway.transaction_search [response.params['status'], response., response.params['type'], response.params['gross_amount'], response.params['gross_amount_currency_id']] end |
#to_express_checkout_url(response, kb_tenant_id = nil, options = {}) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/paypal_express/private_api.rb', line 40 def to_express_checkout_url(response, kb_tenant_id = nil, = {}) payment_processor_account_id = [:payment_processor_account_id] || :default gateway = gateway(payment_processor_account_id, kb_tenant_id) review = ::Killbill::Plugin::ActiveMerchant::Utils.normalized(, :review) gateway.redirect_url_for(response.token, :review => review) end |