Permalink
Browse files

Merge pull request #70 from lucashungaro/feature/support-installments

Support installments
  • Loading branch information...
wvanbergen committed Mar 2, 2014
2 parents 510f0ce + 9db97fd commit 59f5394c1abd1bf869f3af384311e9dbc436d719
@@ -107,6 +107,7 @@ def authorise_one_click_payment_request_body
def payment_request_body(content)
validate_parameters!(:merchant_account, :reference, :amount => [:currency, :value])
content << amount_partial
+ content << installments_partial if @params[:installments]
content << shopper_partial if @params[:shopper]
content << fraud_offset_partial if @params[:fraud_offset]
LAYOUT % [@params[:merchant_account], @params[:reference], content]
@@ -150,15 +151,21 @@ def card_partial
end
end
+ def installments_partial
+ if @params[:installments] and @params[:installments][:value]
+ INSTALLMENTS_PARTIAL % @params[:installments].values_at(:value)
+ end
+ end
+
def shopper_partial
@params[:shopper].map { |k, v| SHOPPER_PARTIALS[k] % v }.join("\n")
end
-
+
def fraud_offset_partial
validate_parameters!(:fraud_offset)
FRAUD_OFFSET_PARTIAL % @params[:fraud_offset]
end
-
+
class AuthorisationResponse < Response
ERRORS = {
"validation 101 Invalid card number" => [:number, 'is not a valid creditcard number'],
@@ -65,6 +65,13 @@ def modification_request_with_amount(method)
</payment:card>
EOS
+ # @private
+ INSTALLMENTS_PARTIAL = <<EOS
+ <payment:installments>
+ <common:value>%s</common:value>
+ </payment:installments>
+EOS
+
# @private
ENCRYPTED_CARD_PARTIAL = <<EOS
<additionalAmount xmlns="http://payment.services.adyen.com" xsi:nil="true" />
@@ -110,7 +117,7 @@ def modification_request_with_amount(method)
:ip => ' <payment:shopperIP>%s</payment:shopperIP>',
:statement => ' <payment:shopperStatement>%s</payment:shopperStatement>',
}
-
+
# @private
FRAUD_OFFSET_PARTIAL = '<payment:fraudOffset>%s</payment:fraudOffset>'
end
View
@@ -30,7 +30,7 @@ def should_map_shortcut_to(method, params)
{ :expiry_month => 12, :expiry_year => 2012, :holder_name => "Simon Hopper", :number => '4444333322221111', :cvc => '737' }
)
end
-
+
it "performs a `authorise payment' request with additional :fraud_offset" do
should_map_shortcut_to(:authorise_payment,
:reference => 'order-id',
@@ -79,7 +79,7 @@ def should_map_shortcut_to(method, params)
{ :reference => 'user-id', :email => 's.hopper@example.com' }
)
end
-
+
it "performs a `authorise recurring payment' request with specific detail" do
should_map_shortcut_to(:authorise_recurring_payment,
:reference => 'order-id',
@@ -94,7 +94,7 @@ def should_map_shortcut_to(method, params)
'recurring-detail-reference'
)
end
-
+
it "performs a `authorise recurring payment' request with specific detail and fraud offset" do
should_map_shortcut_to(:authorise_recurring_payment,
:reference => 'order-id',
@@ -127,7 +127,7 @@ def should_map_shortcut_to(method, params)
'recurring-detail-reference'
)
end
-
+
it "performs a `authorise one-click payment' request with specific detail and fraud offset" do
should_map_shortcut_to(:authorise_one_click_payment,
:reference => 'order-id',
@@ -23,16 +23,27 @@
text('./payment:shopperIP').should == '61.294.12.12'
text('./payment:shopperStatement').should == 'invoice number 123456'
end
-
+
it "includes the fraud offset" do
text('./payment:fraudOffset').should == '30'
end
-
+
it "does not include the fraud offset if none is given" do
@payment.params.delete(:fraud_offset)
xpath('./payment:fraudOffset').should be_empty
end
+ it "includes the given amount of `installments'" do
+ xpath('./payment:installments') do |amount|
+ amount.text('./common:value').should == '6'
+ end
+ end
+
+ it "does not include the installments amount if none is given" do
+ @payment.params.delete(:installments)
+ xpath('./payment:installments').should be_empty
+ end
+
it "only includes shopper details for given parameters" do
# TODO pretty lame, but for now it will do
unless @method == "authorise_one_click_payment_request_body" || @method == "authorise_recurring_payment_request_body"
@@ -95,6 +106,9 @@
#:start_month => ,
#:start_year => ,
},
+ :installments => {
+ :value => 6
+ },
:recurring_detail_reference => 'RecurringDetailReference1',
:fraud_offset => 30
}
@@ -113,7 +127,7 @@
@payment.params[:recurring] = true
@payment.params[:shopper] = nil
end
-
+
it_should_validate_request_param(:fraud_offset) do
@payment.params[:fraud_offset] = ''
end
@@ -226,8 +240,9 @@
it "prepends the error attribute with the given prefix, except for :base" do
[
- ["validation 101 Invalid card number", [:card_number, 'is not a valid creditcard number']],
- ["validation 130 Reference Missing", [:base, "validation 130 Reference Missing"]],
+ ["validation 101 Invalid card number", [:card_number, 'is not a valid creditcard number']],
+ ["validation 130 Reference Missing", [:base, "validation 130 Reference Missing"]],
+ ["validation 152 Invalid number of installments", [:base, "validation 152 Invalid number of installments"]],
].each do |message, error|
response_with_fault_message(message).error(:card).should == error
end

0 comments on commit 59f5394

Please sign in to comment.