class Adyen::API::PaymentService

This is the class that maps actions to Adyen’s Payment SOAP service.

It’s encouraged to use the shortcut methods on the {API} module, which abstracts away the difference between this service and the {RecurringService}. Henceforth, for extensive documentation you should look at the {API} documentation.

The most important difference is that you instantiate a {PaymentService} with the parameters that are needed for the call that you will eventually make.

@example

payment = Adyen::API::PaymentService.new({
  :reference => invoice.id,
  :amount => {
    :currency => 'EUR',
    :value => invoice.amount,
  },
  :shopper => {
    :email => user.email,
    :reference => user.id,
    :ip => request.ip,
    :statement => 'Invoice number 123456'
  },
  :card => {
    :expiry_month => 12,
    :expiry_year => 2012,
    :holder_name => 'Simon Hopper',
    :number => '4444333322221111',
    :cvc => '737'
  }
})
response = payment.authorise_payment
response.authorised? # => true

Constants

AMOUNT_PARTIAL

@private

CANCEL_LAYOUT

@private

CANCEL_OR_REFUND_LAYOUT

@private

CAPTURE_DELAY_PARTIAL

@private

CAPTURE_LAYOUT

@private

CARD_CVC_PARTIAL

@private

CARD_PARTIAL

@private

DELIVERY_DATE_PARTIAL

@private

ENABLE_RECURRING_CONTRACTS_PARTIAL

@private

ENCRYPTED_CARD_PARTIAL

@private

ENDPOINT_URI

The Adyen Payment SOAP service endpoint uri.

FRAUD_OFFSET_PARTIAL

@private

INSTALLMENTS_PARTIAL

@private

LAYOUT

@private

ONE_CLICK_CARD_PARTIAL

@private

ONE_CLICK_PAYMENT_BODY_PARTIAL

@private

RECURRING_PAYMENT_BODY_PARTIAL

@private

REFUND_LAYOUT

@private

SELECTED_BRAND_PARTIAL

@private

SHOPPER_NAME_PARTIAL

@private

SHOPPER_PARTIALS

@private

SHOPPER_STATEMENT

@private

SOCIAL_SECURITY_NUMBER_PARTIAL

Private Class Methods

modification_request(method, body = nil) click to toggle source
   # File lib/adyen/api/templates/payment_service.rb
 7         def modification_request(method, body = nil)
 8           <<-EOXML
 9             <payment:#{method} xmlns:payment="http://payment.services.adyen.com" xmlns:recurring="http://recurring.services.adyen.com" xmlns:common="http://common.services.adyen.com">
10               <payment:modificationRequest>
11                 <payment:merchantAccount>%s</payment:merchantAccount>
12                 <payment:originalReference>%s</payment:originalReference>
13                 #{body}
14               </payment:modificationRequest>
15             </payment:#{method}>
16           EOXML
17         end
modification_request_with_amount(method) click to toggle source
   # File lib/adyen/api/templates/payment_service.rb
19         def modification_request_with_amount(method)
20           modification_request(method, <<-EOXML)
21             <payment:modificationAmount>
22               <common:currency>%s</common:currency>
23               <common:value>%s</common:value>
24             </payment:modificationAmount>
25           EOXML
26         end

Public Instance Methods

authorise_one_click_payment() click to toggle source

@see API.authorise_one_click_payment

   # File lib/adyen/api/payment_service.rb
59 def authorise_one_click_payment
60   make_payment_request(authorise_one_click_payment_request_body, AuthorisationResponse)
61 end
authorise_payment() click to toggle source

@see API.authorise_payment

   # File lib/adyen/api/payment_service.rb
49 def authorise_payment
50   make_payment_request(authorise_payment_request_body, AuthorisationResponse)
51 end
authorise_recurring_payment() click to toggle source

@see API.authorise_recurring_payment

   # File lib/adyen/api/payment_service.rb
54 def authorise_recurring_payment
55   make_payment_request(authorise_recurring_payment_request_body, AuthorisationResponse)
56 end
cancel() click to toggle source

@see API.cancel_payment

   # File lib/adyen/api/payment_service.rb
74 def cancel
75   make_payment_request(cancel_request_body, CancelResponse)
76 end
cancel_or_refund() click to toggle source

@see API.cancel_or_refund_payment

   # File lib/adyen/api/payment_service.rb
79 def cancel_or_refund
80   make_payment_request(cancel_or_refund_request_body, CancelOrRefundResponse)
81 end
capture() click to toggle source

@see API.capture_payment

   # File lib/adyen/api/payment_service.rb
64 def capture
65   make_payment_request(capture_request_body, CaptureResponse)
66 end
generate_billet() click to toggle source

@see API.generate_billet

   # File lib/adyen/api/payment_service.rb
44 def generate_billet
45   make_payment_request(generate_billet_request_body, BilletResponse)
46 end
refund() click to toggle source

@see API.refund_payment

   # File lib/adyen/api/payment_service.rb
69 def refund
70   make_payment_request(refund_request_body, RefundResponse)
71 end

Private Instance Methods

amount_partial() click to toggle source
    # File lib/adyen/api/payment_service.rb
156 def amount_partial
157   AMOUNT_PARTIAL % @params[:amount].values_at(:currency, :value)
158 end
authorise_one_click_payment_request_body() click to toggle source
    # File lib/adyen/api/payment_service.rb
104 def authorise_one_click_payment_request_body
105   validate_parameters!(:recurring_detail_reference,
106                        :shopper => [:email, :reference])
107   content = one_click_card_partial
108   content << ONE_CLICK_PAYMENT_BODY_PARTIAL % [@params[:recurring_detail_reference]]
109   payment_request_body(content)
110 end
authorise_payment_request_body() click to toggle source
   # File lib/adyen/api/payment_service.rb
89 def authorise_payment_request_body
90   content = card_partial
91   if @params[:recurring]
92     validate_parameters!(:shopper => [:email, :reference])
93     content << ENABLE_RECURRING_CONTRACTS_PARTIAL
94   end
95   payment_request_body(content)
96 end
authorise_recurring_payment_request_body() click to toggle source
    # File lib/adyen/api/payment_service.rb
 98 def authorise_recurring_payment_request_body
 99   validate_parameters!(:shopper => [:email, :reference])
100   content = RECURRING_PAYMENT_BODY_PARTIAL % (@params[:recurring_detail_reference] || 'LATEST')
101   payment_request_body(content)
102 end
cancel_or_refund_request_body() click to toggle source
    # File lib/adyen/api/payment_service.rb
141 def cancel_or_refund_request_body
142   validate_parameters!(:merchant_account, :psp_reference)
143   CANCEL_OR_REFUND_LAYOUT % [@params[:merchant_account], @params[:psp_reference]]
144 end
cancel_request_body() click to toggle source
    # File lib/adyen/api/payment_service.rb
146 def cancel_request_body
147   validate_parameters!(:merchant_account, :psp_reference)
148   CANCEL_LAYOUT % [@params[:merchant_account], @params[:psp_reference]]
149 end
capture_and_refund_params() click to toggle source
    # File lib/adyen/api/payment_service.rb
151 def capture_and_refund_params
152   validate_parameters!(:merchant_account, :psp_reference, :amount => [:currency, :value])
153   [@params[:merchant_account], @params[:psp_reference], *@params[:amount].values_at(:currency, :value)]
154 end
capture_delay_partial(delay = 0) click to toggle source
    # File lib/adyen/api/payment_service.rb
225 def capture_delay_partial(delay = 0)
226   CAPTURE_DELAY_PARTIAL % delay
227 end
capture_request_body() click to toggle source
    # File lib/adyen/api/payment_service.rb
133 def capture_request_body
134   CAPTURE_LAYOUT % capture_and_refund_params
135 end
card_partial() click to toggle source
    # File lib/adyen/api/payment_service.rb
174 def card_partial
175   if @params[:card] && @params[:card][:encrypted] && @params[:card][:encrypted][:json]
176     ENCRYPTED_CARD_PARTIAL % [@params[:card][:encrypted][:json]]
177   else
178     validate_parameters!(:card => [:holder_name, :number, :expiry_year, :expiry_month])
179     card  = @params[:card].values_at(:holder_name, :number, :expiry_year)
180     card << @params[:card][:expiry_month].to_i
181     card << (['', nil].include?(@params[:card][:cvc]) ? '' : (CARD_CVC_PARTIAL % @params[:card][:cvc]))
182     CARD_PARTIAL % card
183   end
184 end
delivery_date_partial() click to toggle source
    # File lib/adyen/api/payment_service.rb
204 def delivery_date_partial
205   if @params[:delivery_date]
206     DELIVERY_DATE_PARTIAL % @params[:delivery_date]
207   end
208 end
fraud_offset_partial() click to toggle source
    # File lib/adyen/api/payment_service.rb
220 def fraud_offset_partial
221   validate_parameters!(:fraud_offset)
222   FRAUD_OFFSET_PARTIAL % @params[:fraud_offset]
223 end
generate_billet_request_body() click to toggle source
    # File lib/adyen/api/payment_service.rb
122 def generate_billet_request_body
123   validate_parameters!(:merchant_account, :reference, :amount => [:currency, :value])
124   content  =  amount_partial
125   content << social_security_number_partial if @params[:social_security_number]
126   content << shopper_name_partial if @params[:shopper_name]
127   content << delivery_date_partial if @params[:delivery_date]
128   content << selected_brand_partial if @params[:selected_brand]
129   content << shopper_statement_partial if @params[:shopper_statement]
130   LAYOUT % [@params[:merchant_account], @params[:reference], content]
131 end
installments_partial() click to toggle source
    # File lib/adyen/api/payment_service.rb
186 def installments_partial
187   if @params[:installments] && @params[:installments][:value]
188     INSTALLMENTS_PARTIAL % @params[:installments].values_at(:value)
189   end
190 end
make_payment_request(data, response_class) click to toggle source
   # File lib/adyen/api/payment_service.rb
85 def make_payment_request(data, response_class)
86   call_webservice_action('authorise', data, response_class)
87 end
one_click_card_partial() click to toggle source
    # File lib/adyen/api/payment_service.rb
160 def one_click_card_partial
161   if @params[:card] && @params[:card][:encrypted] && @params[:card][:encrypted][:json]
162     ENCRYPTED_CARD_PARTIAL % [@params[:card][:encrypted][:json]]
163   else
164     validate_parameters!(:card => [:cvc])
165     card  = @params[:card].values_at(:cvc)
166     ONE_CLICK_CARD_PARTIAL % card
167   end
168 end
payment_request_body(content) click to toggle source
    # File lib/adyen/api/payment_service.rb
112 def payment_request_body(content)
113   validate_parameters!(:merchant_account, :reference, :amount => [:currency, :value])
114   content << amount_partial
115   content << installments_partial if @params[:installments]
116   content << shopper_partial if @params[:shopper]
117   content << fraud_offset_partial if @params[:fraud_offset]
118   content << capture_delay_partial if @params[:instant_capture]
119   LAYOUT % [@params[:merchant_account], @params[:reference], content]
120 end
refund_request_body() click to toggle source
    # File lib/adyen/api/payment_service.rb
137 def refund_request_body
138   REFUND_LAYOUT % capture_and_refund_params
139 end
selected_brand_partial() click to toggle source
    # File lib/adyen/api/payment_service.rb
198 def selected_brand_partial
199   if @params[:selected_brand]
200     SELECTED_BRAND_PARTIAL % @params[:selected_brand]
201   end
202 end
shopper_name_partial() click to toggle source
    # File lib/adyen/api/payment_service.rb
170 def shopper_name_partial
171   SHOPPER_NAME_PARTIAL % @params[:shopper_name].values_at(:first_name, :last_name)
172 end
shopper_partial() click to toggle source
    # File lib/adyen/api/payment_service.rb
210 def shopper_partial
211   @params[:shopper].map { |k, v| SHOPPER_PARTIALS[k] % v }.join("\n")
212 end
shopper_statement_partial() click to toggle source
    # File lib/adyen/api/payment_service.rb
214 def shopper_statement_partial
215   if @params[:shopper_statement]
216     SHOPPER_STATEMENT % @params[:shopper_statement]
217   end
218 end
social_security_number_partial() click to toggle source
    # File lib/adyen/api/payment_service.rb
192 def social_security_number_partial
193   if @params[:social_security_number]
194     SOCIAL_SECURITY_NUMBER_PARTIAL % @params[:social_security_number]
195   end
196 end