Class: PaymentRecipes::PayPal::SOAP::Action::CreateExpressCheckout

Inherits:
Utils::Action
  • Object
show all
Defined in:
lib/payment_recipes/paypal/soap/action/create_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

#alternative_redirect_urlObject


88
89
90
# File 'lib/payment_recipes/paypal/soap/action/create_express_checkout_payment.rb', line 88

def alternative_redirect_url
  express_checkout_alternative_redirect_url
end

#get_express_checkout_alternative_redirect_urlObject


76
77
78
79
80
81
82
83
84
85
86
# File 'lib/payment_recipes/paypal/soap/action/create_express_checkout_payment.rb', line 76

def get_express_checkout_alternative_redirect_url
  store(:express_checkout_alternative_redirect_url) do
    paypal_base_url = if api.config.mode == "sandbox"
                        "https://www.sandbox.paypal.com"
                      else
                        "https://www.paypal.com"
                      end

    "#{ paypal_base_url }/webapps/xoonboarding?token=#{ response.token }&useraction=commit"
  end
end

#get_express_checkout_urlObject


64
65
66
67
68
69
70
# File 'lib/payment_recipes/paypal/soap/action/create_express_checkout_payment.rb', line 64

def get_express_checkout_url
  store(:express_checkout_redirect_url) do
    if set_express_checkout_response
      api.express_checkout_url(set_express_checkout_response)
    end
  end
end

#modify_detailsObject


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/payment_recipes/paypal/soap/action/create_express_checkout_payment.rb', line 26

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

    details[:SetExpressCheckoutRequestDetails][:PaymentDetails][0][:PaymentAction] = payment_action

    details
  end
end

#performObject


9
10
11
12
13
14
15
16
17
18
# File 'lib/payment_recipes/paypal/soap/action/create_express_checkout_payment.rb', line 9

def perform
  prepare_soap_api
  modify_details
  set_express_checkout

  get_express_checkout_url
  get_express_checkout_alternative_redirect_url

  express_checkout_redirect_url
end

#prepare_soap_apiObject


20
21
22
23
24
# File 'lib/payment_recipes/paypal/soap/action/create_express_checkout_payment.rb', line 20

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

#redirect_urlObject


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

def redirect_url
  express_checkout_redirect_url
end

#responseObject


60
61
62
# File 'lib/payment_recipes/paypal/soap/action/create_express_checkout_payment.rb', line 60

def response
  set_express_checkout_response
end

#set_express_checkoutObject


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/payment_recipes/paypal/soap/action/create_express_checkout_payment.rb', line 44

def set_express_checkout
  set_express_checkout = api.build_set_express_checkout(express_checkout_details)

  store(:set_express_checkout_response) do
    response = api.set_express_checkout(set_express_checkout)

    unless response.success?
      @error = response.errors

      response = nil
    end

    response
  end
end