lib/adyen/rest/authorise_payment.rb in adyen-2.0.0.pre1 vs lib/adyen/rest/authorise_payment.rb in adyen-2.0.0.pre2

- old
+ new

@@ -12,11 +12,11 @@ end def set_encrypted_card_data(source) encrypted_json = if source.respond_to?(:params) source.params['adyen-encrypted-data'] - elsif source.respond_to?(:[]) && source.key?('adyen-encrypted-data') + elsif source.is_a?(Hash) && source.key?('adyen-encrypted-data') source['adyen-encrypted-data'] else source end @@ -137,12 +137,108 @@ def authorise_payment_3dsecure(attributes) request = authorise_payment_3dsecure_request(attributes) execute_request(request) end + # Generates <tt>Payment.authorise</tt> request with recurring for Adyen's webservice. + # @param (see #authorise_recurring_payment) + # @return [Adyen::REST::Request] The request to send + # @see #authorise_recurring_payment + def authorise_recurring_payment_request(attributes={}) + Adyen::REST::AuthoriseRecurringPayment::Request.new('Payment.authorise', attributes, + prefix: 'payment_request', + response_class: Adyen::REST::AuthorisePayment::Response, + response_options: { prefix: 'payment_result' }) + end + + # Sends an authorise recurring payment request to Adyen's webservice. + # @param attributes [Hash] The attributes to include in the request. + # @return [Adyen::REST::AuthorisePayment::Response] The response from Adyen. + # The response responds to <tt>.authorised?</tt> to check whether the + # authorization was successful. + # @see Adyen::REST::AuthorisePayment::Response#authorised? + def authorise_recurring_payment(attributes) + request = authorise_recurring_payment_request(attributes) + execute_request(request) + end + + # Generates <tt>Payment.authorise</tt> request with recurring for Adyen's webservice. + # This method can be called if a previous contract was established with #authorise_recurring_payment + # @param (see #authorise_recurring_payment) + # @return [Adyen::REST::Request] The request to send + # @see #authorise_recurring_payment + def reauthorise_recurring_payment_request(attributes={}) + Adyen::REST::ReauthoriseRecurringPayment::Request.new('Payment.authorise', attributes, + prefix: 'payment_request', + response_class: Adyen::REST::AuthorisePayment::Response, + response_options: { prefix: 'payment_result' }) + end + + # Sends an authorise recurring payment request to Adyen's webservice. + # This method can be called if a previous contract was established with #authorise_recurring_payment + # @param attributes [Hash] The attributes to include in the request. + # @return [Adyen::REST::AuthorisePayment::Response] The response from Adyen. + # The response responds to <tt>.authorised?</tt> to check whether the + # authorization was successful. + # @see Adyen::REST::AuthorisePayment::Response#authorised? + def reauthorise_recurring_payment(attributes) + request = reauthorise_recurring_payment_request(attributes) + execute_request(request) + end + + # The Response class implements some extensions for the list recurring details call. + # @see Adyen::REST::Response + class ListRecurringDetailsResponse < Adyen::REST::Response + # Returns a list of recurring details + # @return [Array] A not empty array if there is at least a recurring detail + def details + mapped_attributes = { + :recurring_detail_reference => "recurringDetailReference", + :creation_date => "creationDate", + :variant => "variant", + :card_holder_name => "card.holderName", + :card_expiry_month => "card.expiryMonth", + :card_expiry_year => "card.expiryYear", + :card_number => "card.number" + } + + map_response_list("recurringDetailsResult.details", mapped_attributes) + end + + # Returns a list of recurring details references + # @return [Array] A not empty array if there is at least a recurring detail reference + def references + details.map { |detail| detail[:recurring_detail_reference] } + end + end + + # Generates <tt>Recurring.listRecurringDetails</tt> request for Adyen's webservice. + # @param (see #list_recurring_details) + # @return [Adyen::REST::ListRecurringDetailsPayment::Request] The request to send + # @see #list_recurring_details + def list_recurring_details_request(attributes = {}) + Adyen::REST::ListRecurringDetailsPayment::Request.new('Recurring.listRecurringDetails', attributes, + prefix: 'recurring_details_request', + response_class: Adyen::REST::AuthorisePayment::ListRecurringDetailsResponse, + response_options: { prefix: 'recurring_details_result' }) + end + + # Sends an list recurring details request to Adyen's webservice. + # @param attributes [Hash] The attributes to include in the request. + # @return [Adyen::REST::AuthorisePayment::ListRecurringDetailsResponse] The response from Adyen. + # The response responds to <tt>.details</tt> and <tt>.references</tt> with recurring data. + # @see Adyen::REST::AuthorisePayment::ListRecurringDetailsResponse#references + # @see Adyen::REST::AuthorisePayment::ListRecurringDetailsResponse#details + def list_recurring_details(attributes) + request = list_recurring_details_request(attributes) + execute_request(request) + end + alias_method :authorize_payment_request, :authorise_payment_request alias_method :authorize_payment, :authorise_payment alias_method :authorize_payment_3dsecure_request, :authorise_payment_3dsecure_request alias_method :authorize_payment_3dsecure, :authorise_payment_3dsecure + alias_method :reauthorize_recurring_payment_request, :reauthorise_recurring_payment_request + alias_method :reauthorize_recurring_payment, :reauthorise_recurring_payment end end end