Class: PaymentRecipes::PayPal::SOAP::Action::ExecuteExpressCheckout

Inherits:
Utils::Action
  • Object
show all
Defined in:
lib/payment_recipes/paypal/soap/action/execute_express_checkout_payment.rb

Instance Method Summary collapse

Methods inherited from Utils::Action

#debug, debug, #ensure_presence, #execute, #failure?, #get, #initialize, #make_instance_variables_available, prepare, rules, #set, #store, #stored_variables, #success?, variable

Constructor Details

This class inherits a constructor from PaymentRecipes::Utils::Action

Instance Method Details

#do_express_checkoutObject



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/payment_recipes/paypal/soap/action/execute_express_checkout_payment.rb', line 104

def do_express_checkout
  do_express_checkout_payment = api.build_do_express_checkout_payment(express_checkout_details)

  store(:do_express_checkout_response) do
    response = api.do_express_checkout_payment(do_express_checkout_payment)

    unless response.success?
      @error = response.errors

      response = nil
    end

    response
  end
end

#load_transactionObject



120
121
122
123
124
125
126
# File 'lib/payment_recipes/paypal/soap/action/execute_express_checkout_payment.rb', line 120

def load_transaction
  store(:transaction) do
    transaction_id = response.do_express_checkout_payment_response_details.payment_info.first.transaction_id
    
    ::PaymentRecipes::PayPal::SOAP::Transaction.find(transaction_id)
  end
end

#modify_detailsObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/payment_recipes/paypal/soap/action/execute_express_checkout_payment.rb', line 77

def modify_details
  unless [:sale, :authorize].include?(intent)
    raise Exception, "Allowed values for intent: :sale, :authorize"
  end

  store(:express_checkout_details) do
    payment_action = if intent == :sale
                       'Sale'
                     elsif intent == :authorize
                       'Authorization'
                     end

    {
      :DoExpressCheckoutPaymentRequestDetails => {
        :PaymentAction => payment_action,
        :Token => token,
        :PayerID => payer_id,
        :PaymentDetails => [details] 
      } 
    }
  end
end

#performObject



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/payment_recipes/paypal/soap/action/execute_express_checkout_payment.rb', line 59

def perform
  prepare_soap_api
  modify_details
  do_express_checkout

  if response.success?
    load_transaction
  end

  response
end

#prepare_soap_apiObject



71
72
73
74
75
# File 'lib/payment_recipes/paypal/soap/action/execute_express_checkout_payment.rb', line 71

def prepare_soap_api
  store(:api) do
    ::PaymentRecipes::PayPal::SOAP::Settings.api
  end
end

#responseObject



100
101
102
# File 'lib/payment_recipes/paypal/soap/action/execute_express_checkout_payment.rb', line 100

def response
  do_express_checkout_response
end