Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #23 from luki3k5/adyen

---

Hello Everyone,

I have added the ELV payment option for German users. Please review this request to pull code into main trunk of adyen gem. 

Thank You
Lukasz
  • Loading branch information...
commit f9ac02b2cebd438bd547fca85d8238d029518161 2 parents 2b02681 + 04440d8
@wvanbergen wvanbergen authored
View
41 lib/adyen/api.rb
@@ -318,5 +318,46 @@ def store_recurring_token(shopper, card)
:card => card
}).store_token
end
+
+ # Stores and tokenises the ELV (Elektronisches Lastschriftverfahren)
+ # details so that recurring payments can be made in the future.
+ #
+ # # @example
+ # response = Adyen::API.store_recurring_token_using_elv(
+ # { :reference => user.id, :email => user.email, :ip => '8.8.8.8' },
+ # { :bank_location => "Berlin", :bank_name => "TestBank", :bank_location_id => "12345678", :account_holder_name => user.full_name, :bank_account_number => "1234567890" }
+ # )
+ # response.stored? # => true
+ #
+ # # Now we can authorize a payment with the token.
+ # authorize_response = Adyen::API.authorise_recurring_payment(
+ # invoice.id,
+ # { :currency => 'EUR', :value => invoice.amount },
+ # { :reference => user.id, :email => user.email, :ip => '8.8.8.8' },
+ # response.recurring_detail_reference
+ # )
+ # authorize_response.authorised? # => true
+ #
+ # @param [Hash] shopper A hash describing the shopper.
+ # @param [Hash] elv A hash describing the ELV (Elektronisches Lastschriftverfahren) details.
+ #
+ # @option shopper [Numeric,String] :reference The shopper’s reference (ID).
+ # @option shopper [String] :email The shopper’s email address.
+ # @option shopper [String] :ip The shopper’s IP address.
+ #
+ # @option elv [String] :bank_location The Bank Location.
+ # @option elv [String] :bank_name The Bank Name.
+ # @option elv [Numeric,String] :bank_location_id The Bank Location ID (Bankleitzahl).
+
+ # @option elv [String] :account_holder_name The holder's full name on the account.
+ # @option elv [Numeric,String] :bank_account_number The account number.
+ #
+ # @return [RecurringService::StoreTokenResponse] The response object
+ def store_recurring_token_using_elv(shopper, elv)
+ RecurringService.new({
+ :shopper => shopper,
+ :elv => elv
+ }).store_token
+ end
end
end
View
35 lib/adyen/api/recurring_service.rb
@@ -45,6 +45,13 @@ def card_partial
card << @params[:card][:expiry_month].to_i
CARD_PARTIAL % card
end
+
+ # The ELV - (Elektronisches Lastschriftverfahren) does not require bank_location, so insert 'nil'.
+ def elv_partial
+ validate_parameters!(:elv => [:bank_location, :bank_name, :bank_location_id, :account_holder_name, :bank_account_number])
+ elv = @params[:elv].values_at(:bank_location, :bank_name, :bank_location_id, :account_holder_name, :bank_account_number)
+ ELV_PARTIAL % elv
+ end
def list_request_body
validate_parameters!(:merchant_account, :shopper => [:reference])
@@ -61,7 +68,10 @@ def disable_request_body
def store_token_request_body
validate_parameters!(:merchant_account, :shopper => [:email, :reference])
- content = card_partial
+ content = []
+ content << card_partial unless @params[:card].nil?
+ content << elv_partial unless @params[:elv].nil?
+ raise " recurring_service#store_token_request_body() failed to set content nor card or elv passed! " if content.empty?
STORE_TOKEN_LAYOUT % [@params[:merchant_account], @params[:shopper][:reference], @params[:shopper][:email], content]
end
@@ -111,12 +121,17 @@ def parse_recurring_detail(node)
}
card = node.xpath('./recurring:card')
- if card.children.empty?
- result[:bank] = parse_bank_details(node.xpath('./recurring:bank'))
- else
+ elv = node.xpath('./recurring:elv')
+ bank = node.xpath('./recurring:bank')
+
+ if !card.children.empty?
result[:card] = parse_card_details(card)
+ elsif !elv.children.empty?
+ result[:elv] = parse_elv_details(elv)
+ else
+ result[:bank] = parse_bank_details(bank)
end
-
+
result
end
@@ -128,6 +143,16 @@ def parse_card_details(card)
}
end
+ def parse_elv_details(elv)
+ {
+ :account_holder_name => bank.text('./payment:accountHolderName'),
+ :bank_account_number => bank.text('./payment:bankAccountNumber'),
+ :bank_location => bank.text('./payment:bankLocation'),
+ :bank_location_id => bank.text('./payment:bankLocationId'),
+ :bank_name => bank.text('./payment:bankName')
+ }
+ end
+
def parse_bank_details(bank)
{
:bank_account_number => bank.text('./payment:bankAccountNumber'),
View
12 lib/adyen/api/templates/recurring_service.rb
@@ -54,6 +54,18 @@ class RecurringService < SimpleSOAPClient
<payment:expiryMonth>%02d</payment:expiryMonth>
</recurring:card>
EOS
+ # Electronic bank debit in Germany. Semi real-time payment method.
+ # @private
+ ELV_PARTIAL = <<EOS
+ <recurring:elv>
+ <payment:bankLocation>%s</payment:bankLocation>
+ <payment:bankName>%s</payment:bankName>
+ <payment:bankLocationId>%s</payment:bankLocationId>
+ <payment:accountHolderName>%s</payment:accountHolderName>
+ <payment:bankAccountNumber>%02d</payment:bankAccountNumber>
+ </recurring:elv>
+EOS
+
end
end
end
View
11 spec/api/api_spec.rb
@@ -131,6 +131,17 @@ def should_map_shortcut_to(method, params)
)
end
+ it "performs a `tokenize ELV details' request" do
+ should_map_shortcut_to(:store_token,
+ :shopper => { :reference => 'user-id', :email => 's.hopper@example.com' },
+ :elv => { :bank_location => "Berlin", :bank_name => "TestBank", :bank_location_id => "12345678", :account_holder_name => "Simon Hopper", :bank_account_number => "1234567890" }
+ )
+ Adyen::API.store_recurring_token_using_elv(
+ { :reference => 'user-id', :email => 's.hopper@example.com' },
+ { :bank_location => "Berlin", :bank_name => "TestBank", :bank_location_id => "12345678", :account_holder_name => "Simon Hopper", :bank_account_number => "1234567890" }
+ )
+ end
+
it "preforms a `list recurring details' request" do
should_map_shortcut_to(:list, :shopper => { :reference => 'user-id' })
Adyen::API.list_recurring_details('user-id')
View
40 spec/api/recurring_service_spec.rb
@@ -27,6 +27,14 @@
#:issue_number => ,
#:start_month => ,
#:start_year => ,
+ },
+ # German's Direct Debit (Elektronisches Lastschriftverfahren)
+ :elv => {
+ :account_holder_name => 'Simon わくわく Hopper',
+ :bank_account_number => '1234567890',
+ :bank_location => 'Berlin',
+ :bank_location_id => '12345678',
+ :bank_name => 'TestBank',
}
}
@recurring = @object = Adyen::API::RecurringService.new(@params)
@@ -161,6 +169,38 @@
text('./recurring:recurring/payment:contract').should == 'RECURRING'
end
end
+
+ describe_request_body_of :store_token, '//recurring:storeToken/recurring:request' do
+ it_should_validate_request_parameters :merchant_account,
+ :shopper => [:email, :reference]
+
+ it "includes the merchant account handle" do
+ text('./recurring:merchantAccount').should == 'SuperShopper'
+ end
+
+ it "includes the shopper’s reference" do
+ text('./recurring:shopperReference').should == 'user-id'
+ end
+
+ it "includes the shopper’s email" do
+ text('./recurring:shopperEmail').should == 's.hopper@example.com'
+ end
+
+ it "includes the ELV details" do
+ xpath('./recurring:elv') do |elv|
+ # there's no reason why Nokogiri should escape these characters, but as long as they're correct
+ elv.text('./payment:accountHolderName').should == 'Simon &#x308F;&#x304F;&#x308F;&#x304F; Hopper'
+ elv.text('./payment:bankAccountNumber').should == '1234567890'
+ elv.text('./payment:bankLocation').should == 'Berlin'
+ elv.text('./payment:bankLocationId').should == '12345678'
+ elv.text('./payment:bankName').should == 'TestBank'
+ end
+ end
+
+ it "includes the necessary recurring and one-click contract info if the `:recurring' param is truthful" do
+ text('./recurring:recurring/payment:contract').should == 'RECURRING'
+ end
+ end
describe_response_from :disable, (DISABLE_RESPONSE % '[detail-successfully-disabled]'), 'disable' do
it "returns whether or not it was disabled" do
View
9 spec/functional/api_spec.rb
@@ -57,6 +57,15 @@ def perform_payment_request
response.psp_reference.should_not be_empty
end
+ it "stores the provided ELV account details" do
+ response = Adyen::API.store_recurring_token_using_elv(
+ { :email => "#{@user_id}@example.com", :reference => @user_id },
+ { :bank_location => "Berlin", :bank_name => "TestBank", :bank_location_id => "12345678", :account_holder_name => "Simon #{@user_id} Hopper", :bank_account_number => "1234567890" }
+ )
+ response.should be_stored
+ response.recurring_detail_reference.should_not be_empty
+ end
+
it "stores the provided creditcard details" do
response = Adyen::API.store_recurring_token(
{ :email => "#{@user_id}@example.com", :reference => @user_id },
Please sign in to comment.
Something went wrong with that request. Please try again.