Sha256: 912b883bb4bb0f3bf42c2e4a7572ca228067a7a6effbdabdab2c520b9152f4ea

Contents?: true

Size: 1.86 KB

Versions: 3

Compression:

Stored size: 1.86 KB

Contents

module Killbill #:nodoc:
  module PaypalExpress #:nodoc:
    class PrivatePaymentPlugin < ::Killbill::Plugin::ActiveMerchant::PrivatePaymentPlugin
      def initialize(session = {})
        super(:paypal_express,
              ::Killbill::PaypalExpress::PaypalExpressPaymentMethod,
              ::Killbill::PaypalExpress::PaypalExpressTransaction,
              ::Killbill::PaypalExpress::PaypalExpressResponse,
              session)
      end

      # See https://cms.paypal.com/uk/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_ECReferenceTxns
      def initiate_express_checkout(kb_account_id, kb_tenant_id, amount_in_cents=0, currency='USD', options = {})
        payment_processor_account_id = (options[:payment_processor_account_id] || :default)

        options[:currency]          ||= currency

        # Required arguments
        options[:return_url]        ||= 'http://www.example.com/success'
        options[:cancel_return_url] ||= 'http://www.example.com/sad_panda'

        options[:billing_agreement]               ||= {}
        options[:billing_agreement][:type]        ||= 'MerchantInitiatedBilling'
        options[:billing_agreement][:description] ||= 'Kill Bill billing agreement'

        # Go to Paypal (SetExpressCheckout call)
        paypal_express_response                   = gateway.setup_authorization(amount_in_cents, options)
        response, transaction                     = save_response_and_transaction(paypal_express_response, :initiate_express_checkout, kb_account_id, kb_tenant_id, payment_processor_account_id)

        response
      end

      def to_express_checkout_url(response, options = {})
        payment_processor_account_id = options[:payment_processor_account_id] || :default
        gateway                      = gateway(payment_processor_account_id)
        gateway.redirect_url_for(response.token)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
killbill-paypal-express-1.8.1 lib/paypal_express/private_api.rb
killbill-paypal-express-1.8.0 lib/paypal_express/private_api.rb
killbill-paypal-express-1.7.1 lib/paypal_express/private_api.rb