Last active
August 29, 2015 14:01
-
-
Save huoxito/260afd90010e9c34bb2b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'httparty' | |
Spree::CheckoutController.class_eval do | |
include Spree::Adyen::CheckoutRescue | |
Spree::Payment.send :attr_accessor, :request_env | |
Spree::PermittedAttributes.payment_attributes.push request_env: ['HTTP_USER_AGENT', 'HTTP_ACCEPT'] | |
Spree::PermittedAttributes.source_attributes.push :customer_enabled | |
before_filter :set_payment_request_env, only: :update | |
before_filter :allow_adyen_origin | |
private | |
def set_payment_request_env | |
if params[:order] && params[:order][:payments_attributes] | |
params[:order][:payments_attributes].first[:request_env] = request.headers.env | |
end | |
end | |
def allow_adyen_origin | |
if @order.payment? && params[:state] == "payment" | |
payment_method = @order.available_payment_methods.last | |
redirect_params = { | |
:currency_code => Spree::Config.currency, | |
:ship_before_date => Date.tomorrow, | |
:session_validity => 10.minutes.from_now, | |
:recurring => false, | |
:merchant_reference => "#{@order.number}", | |
:merchant_account => payment_method.preferred_merchant_account, | |
:skin_code => payment_method.preferred_skin_code, | |
:shared_secret => payment_method.preferred_shared_secret, | |
:payment_amount => (@order.total.to_f * 100).to_int | |
} | |
methods = HTTParty.get ::Adyen::Form.payment_methods_url(redirect_params.merge(countryCode: "US")) | |
@hpp_payment_methods = methods.is_a?(Hash) ? methods["paymentMethods"] || {} : {} | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment