Class: Paypal::Express::Request

Inherits:
NVP::Request show all
Defined in:
lib/paypal/express/request.rb

Constant Summary

Constants inherited from NVP::Request

NVP::Request::ENDPOINT

Instance Attribute Summary

Attributes inherited from NVP::Request

#version

Instance Method Summary collapse

Methods inherited from NVP::Request

#common_params, endpoint, #initialize, #request

Methods inherited from Base

#initialize

Methods included from Util

#==, formatted_amount, #numeric_attribute?, to_numeric

Constructor Details

This class inherits a constructor from Paypal::NVP::Request

Instance Method Details

#agree!(token, options = {}) ⇒ Object

Reference Transaction Specific



87
88
89
90
91
92
93
94
95
96
# File 'lib/paypal/express/request.rb', line 87

def agree!(token, options = {})
  params = {
    :TOKEN => token
  }
  if options[:max_amount]
    params[:MAXAMT] = Util.formatted_amount options[:max_amount]
  end
  response = self.request :CreateBillingAgreement, params
  Response.new response
end

#agreement(reference_id) ⇒ Object



98
99
100
101
102
103
104
# File 'lib/paypal/express/request.rb', line 98

def agreement(reference_id)
  params = {
    :REFERENCEID => reference_id,
  }
  response = self.request :BillAgreementUpdate, params
  Response.new response
end

#cancel!(profile_id, options = {}) ⇒ Object



76
77
78
# File 'lib/paypal/express/request.rb', line 76

def cancel!(profile_id, options = {})
  renew!(profile_id, :Cancel, options)
end

#charge!(reference_id, amount, options = {}) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/paypal/express/request.rb', line 106

def charge!(reference_id, amount, options = {})
  params = {
    :REFERENCEID => reference_id,
    :AMT => Util.formatted_amount(amount),
    :PAYMENTACTION => options[:payment_action] || :Sale
  }
  if options[:currency_code]
    params[:CURRENCYCODE] = options[:currency_code]
  end
  response = self.request :DoReferenceTransaction, params
  Response.new response
end

#checkout!(token, payer_id, payment_requests) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/paypal/express/request.rb', line 28

def checkout!(token, payer_id, payment_requests)
  params = {
    :TOKEN => token,
    :PAYERID => payer_id
  }
  Array(payment_requests).each_with_index do |payment_request, index|
    params.merge! payment_request.to_params(index)
  end
  response = self.request :DoExpressCheckoutPayment, params
  Response.new response
end

#details(token) ⇒ Object



23
24
25
26
# File 'lib/paypal/express/request.rb', line 23

def details(token)
  response = self.request :GetExpressCheckoutDetails, {:TOKEN => token}
  Response.new response
end

#reactivate!(profile_id, options = {}) ⇒ Object



80
81
82
# File 'lib/paypal/express/request.rb', line 80

def reactivate!(profile_id, options = {})
  renew!(profile_id, :Reactivate, options)
end

#refund!(transaction_id, options = {}) ⇒ Object

Refund Specific



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/paypal/express/request.rb', line 131

def refund!(transaction_id, options = {})
  params = {
    :TRANSACTIONID => transaction_id,
    :REFUNDTYPE => :Full
  }
  if options[:invoice_id]
    params[:INVOICEID] = options[:invoice_id]
  end
  if options[:type]
    params[:REFUNDTYPE] = options[:type]
    params[:AMT] = options[:amount]
    params[:CURRENCYCODE] = options[:currency_code]
  end
  if options[:note]
    params[:NOTE] = options[:note]
  end
  response = self.request :RefundTransaction, params
  Response.new response
end

#renew!(profile_id, action, options = {}) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/paypal/express/request.rb', line 60

def renew!(profile_id, action, options = {})
  params = {
    :PROFILEID => profile_id,
    :ACTION => action
  }
  if options[:note]
    params[:NOTE] = options[:note]
  end
  response = self.request :ManageRecurringPaymentsProfileStatus, params
  Response.new response
end

#revoke!(reference_id) ⇒ Object



119
120
121
122
123
124
125
126
# File 'lib/paypal/express/request.rb', line 119

def revoke!(reference_id)
  params = {
    :REFERENCEID => reference_id,
    :BillingAgreementStatus => :Canceled
  }
  response = self.request :BillAgreementUpdate, params
  Response.new response
end

#setup(payment_requests, return_url, cancel_url, options = {}) ⇒ Object

Common



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/paypal/express/request.rb', line 7

def setup(payment_requests, return_url, cancel_url, options = {})
  params = {
    :RETURNURL => return_url,
    :CANCELURL => cancel_url
  }
  if options[:no_shipping]
    params[:REQCONFIRMSHIPPING] = 0
    params[:NOSHIPPING] = 1
  end
  Array(payment_requests).each_with_index do |payment_request, index|
    params.merge! payment_request.to_params(index)
  end
  response = self.request :SetExpressCheckout, params
  Response.new response, options
end

#subscribe!(token, recurring_profile) ⇒ Object

Recurring Payment Specific



43
44
45
46
47
48
49
50
# File 'lib/paypal/express/request.rb', line 43

def subscribe!(token, recurring_profile)
  params = {
    :TOKEN => token
  }
  params.merge! recurring_profile.to_params
  response = self.request :CreateRecurringPaymentsProfile, params
  Response.new response
end

#subscription(profile_id) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/paypal/express/request.rb', line 52

def subscription(profile_id)
  params = {
    :PROFILEID => profile_id
  }
  response = self.request :GetRecurringPaymentsProfileDetails, params
  Response.new response
end

#suspend!(profile_id, options = {}) ⇒ Object



72
73
74
# File 'lib/paypal/express/request.rb', line 72

def suspend!(profile_id, options = {})
  renew!(profile_id, :Suspend, options)
end