docdata 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.coveralls.yml +2 -0
  3. data/.gitignore +4 -1
  4. data/.travis.yml +10 -0
  5. data/LICENSE +1 -1
  6. data/README.md +173 -7
  7. data/Rakefile +8 -0
  8. data/docdata.gemspec +18 -11
  9. data/lib/docdata.rb +74 -1
  10. data/lib/docdata/bank.rb +27 -0
  11. data/lib/docdata/config.rb +41 -0
  12. data/lib/docdata/docdata_error.rb +8 -0
  13. data/lib/docdata/engine.rb +13 -0
  14. data/lib/docdata/ideal.rb +40 -0
  15. data/lib/docdata/line_item.rb +99 -0
  16. data/lib/docdata/payment.rb +196 -0
  17. data/lib/docdata/response.rb +173 -0
  18. data/lib/docdata/shopper.rb +112 -0
  19. data/lib/docdata/version.rb +1 -1
  20. data/lib/docdata/xml/bank-list.xml +39 -0
  21. data/lib/docdata/xml/cancel.xml.erb +9 -0
  22. data/lib/docdata/xml/create.xml.erb +98 -0
  23. data/lib/docdata/xml/start.xml.erb +67 -0
  24. data/lib/docdata/xml/status.xml.erb +9 -0
  25. data/php-example/create.xml.erb +140 -0
  26. data/php-example/index.html +78 -0
  27. data/php-example/process.php +182 -0
  28. data/php-example/return.php +36 -0
  29. data/php-example/soap.rb +21 -0
  30. data/spec/config_spec.rb +53 -0
  31. data/spec/ideal_spec.rb +19 -0
  32. data/spec/line_item_spec.rb +55 -0
  33. data/spec/payment_spec.rb +162 -0
  34. data/spec/response_spec.rb +206 -0
  35. data/spec/shopper_spec.rb +50 -0
  36. data/spec/spec_helper.rb +36 -0
  37. data/spec/xml/status-canceled-creditcard.xml +34 -0
  38. data/spec/xml/status-canceled-ideal.xml +29 -0
  39. data/spec/xml/status-new.xml +20 -0
  40. data/spec/xml/status-paid-creditcard.xml +33 -0
  41. data/spec/xml/status-paid-ideal.xml +33 -0
  42. data/spec/xml/status-paid-sofort.xml +33 -0
  43. metadata +145 -13
  44. data/LICENSE.txt +0 -22
@@ -0,0 +1,112 @@
1
+ module Docdata
2
+
3
+ # Creates a validator
4
+ class ShopperValidator
5
+ include Veto.validator
6
+ validates :id, presence: true
7
+ validates :first_name, presence: true
8
+ validates :last_name, presence: true
9
+ validates :street, presence: true
10
+ validates :house_number, presence: true
11
+ validates :postal_code, presence: true
12
+ validates :city, presence: true
13
+ validates :email, presence: true
14
+ validates :country_code, presence: true, format: /[A-Z]{2}/
15
+ validates :language_code, presence: true, format: /[a-z]{2}/
16
+ end
17
+
18
+
19
+
20
+ #
21
+ # Object representing a "Shopper"
22
+ #
23
+ # @example
24
+ # Shopper.new({
25
+ # :first_name => "Jack",
26
+ # :last_name => "Sixpack"
27
+ # :id => "MC123"
28
+ # })
29
+ # @param format [String] The shopper ID
30
+ # @param format [String] Shopper first name
31
+ # @param format [String] Shopper last name
32
+ # @param format [String] Shopper street address
33
+ # @param format [String] Shopper house number
34
+ # @param format [String] Shopper postal code
35
+ # @param format [String] Shopper city
36
+ # @param format [String] Shopper email
37
+ # @param format [String] ISO country code (us, nl, de, uk)
38
+ # @param format [String] ISO language code (en, nl, de)
39
+ class Shopper
40
+
41
+ # @return [Array] Errors
42
+ attr_accessor :errors
43
+ attr_accessor :id
44
+ attr_accessor :first_name
45
+ attr_accessor :last_name
46
+ attr_accessor :street
47
+ attr_accessor :house_number
48
+ attr_accessor :postal_code
49
+ attr_accessor :city
50
+ attr_accessor :email
51
+ attr_accessor :country_code
52
+ attr_accessor :language_code
53
+
54
+
55
+
56
+
57
+ #
58
+ # Initializer to transform a +Hash+ into an Shopper object
59
+ #
60
+ # @param [Hash] args
61
+ def initialize(args=nil)
62
+ self.set_default_values
63
+ return if args.nil?
64
+ args.each do |k,v|
65
+ instance_variable_set("@#{k}", v) unless v.nil?
66
+ end
67
+
68
+ end
69
+
70
+ def name
71
+ "#{first_name} #{last_name}"
72
+ end
73
+
74
+ # Returns true if this instanciated object is valid
75
+ def valid?
76
+ validator = ShopperValidator.new
77
+ validator.valid?(self)
78
+ end
79
+
80
+
81
+ def set_default_values
82
+ @first_name = "First Name"
83
+ @last_name = "Last Name"
84
+ @street = "Main Street"
85
+ @house_number = "123"
86
+ @postal_code = "2244"
87
+ @city = "City"
88
+ @country_code = "NL"
89
+ @language_code = "nl"
90
+ @email = "random@example.com"
91
+ end
92
+
93
+ # This method will instanciate and return a new Shopper object
94
+ # with all the required properties set. Mostly for testing purpose,
95
+ # but maybe usefull in other scenarios as well.
96
+ def self.create_valid_shopper
97
+ shopper = self.new
98
+ shopper.id = "789"
99
+ shopper.first_name = "John"
100
+ shopper.last_name = "Doe"
101
+ shopper.country_code = "NL"
102
+ shopper.language_code = "nl"
103
+ shopper.email = "test@example.org"
104
+ shopper.street = "Main street"
105
+ shopper.house_number = "123"
106
+ shopper.postal_code = "1122AB"
107
+ shopper.city = "Test City"
108
+ return shopper
109
+ end
110
+
111
+ end
112
+ end
@@ -1,3 +1,3 @@
1
1
  module Docdata
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,39 @@
1
+ <response>
2
+ <bank>
3
+ <bank_id>0031</bank_id>
4
+ <bank_name>ABN AMRO</bank_name>
5
+ </bank>
6
+ <bank>
7
+ <bank_id>0761</bank_id>
8
+ <bank_name>ASN Bank</bank_name>
9
+ </bank>
10
+ <bank>
11
+ <bank_id>0721</bank_id>
12
+ <bank_name>ING</bank_name>
13
+ </bank>
14
+ <bank>
15
+ <bank_id>0801</bank_id>
16
+ <bank_name>Knab</bank_name>
17
+ </bank>
18
+ <bank>
19
+ <bank_id>0021</bank_id>
20
+ <bank_name>Rabobank</bank_name>
21
+ </bank>
22
+ <bank>
23
+ <bank_id>0771</bank_id>
24
+ <bank_name>RegioBank</bank_name>
25
+ </bank>
26
+ <bank>
27
+ <bank_id>0751</bank_id>
28
+ <bank_name>SNS Bank</bank_name>
29
+ </bank>
30
+ <bank>
31
+ <bank_id>0511</bank_id>
32
+ <bank_name>Triodos Bank</bank_name>
33
+ </bank>
34
+ <bank>
35
+ <bank_id>0161</bank_id>
36
+ <bank_name>van Lanschot</bank_name>
37
+ </bank>
38
+ <message>This is the current list of banks and their ID's that currently support iDEAL-payments</message>
39
+ </response>
@@ -0,0 +1,9 @@
1
+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:_1="http://www.docdatapayments.com/services/paymentservice/1_1/">
2
+ <soapenv:Header/>
3
+ <soapenv:Body>
4
+ <_1:cancelRequest version="1.1">
5
+ <_1:merchant name="<%=Docdata.username%>" password="Docdata.password"/>
6
+ <_1:paymentOrderKey><%= payment.key %></_1:paymentOrderKey>
7
+ </_1:cancelRequest>
8
+ </soapenv:Body>
9
+ </soapenv:Envelope>
@@ -0,0 +1,98 @@
1
+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:_1="http://www.docdatapayments.com/services/paymentservice/1_1/">
2
+ <soapenv:Header/>
3
+ <soapenv:Body>
4
+ <_1:createRequest version="1.1">
5
+ <_1:merchant name="<%= Docdata.username %>" password="<%= Docdata.password %>"/>
6
+ <_1:merchantOrderReference><%= payment.order_reference %></_1:merchantOrderReference>
7
+ <_1:paymentPreferences>
8
+ <_1:profile><%= payment.profile %></_1:profile>
9
+ <_1:numberOfDaysToPay>14</_1:numberOfDaysToPay>
10
+ </_1:paymentPreferences>
11
+
12
+ <_1:shopper id="<%= shopper.id %>">
13
+ <_1:name>
14
+ <_1:first><%= shopper.first_name %></_1:first>
15
+ <_1:last><%= shopper.last_name %></_1:last>
16
+ </_1:name>
17
+ <_1:email><%= shopper.email %></_1:email>
18
+ <_1:language code="<%= shopper.language_code %>"/>
19
+ <_1:gender>M</_1:gender>
20
+
21
+ </_1:shopper>
22
+ <_1:totalGrossAmount currency="<%= payment.currency %>"><%= payment.amount %></_1:totalGrossAmount>
23
+ <_1:billTo>
24
+ <_1:name>
25
+ <_1:first><%= shopper.first_name %></_1:first>
26
+ <_1:last><%= shopper.last_name %></_1:last>
27
+ </_1:name>
28
+ <_1:address>
29
+ <_1:street><%= shopper.street %></_1:street>
30
+ <_1:houseNumber><%= shopper.house_number %></_1:houseNumber>
31
+ <_1:postalCode><%= shopper.postal_code %></_1:postalCode>
32
+ <_1:city><%= shopper.city %></_1:city>
33
+ <_1:country code="<%= shopper.country_code %>"/>
34
+ </_1:address>
35
+ </_1:billTo>
36
+
37
+ <% if payment.description.present? %>
38
+ <_1:description><%= payment.description %></_1:description>
39
+ <% end %>
40
+ <% if payment.receipt_text.present? %>
41
+ <_1:receiptText><%= payment.receipt_text %></_1:receiptText>
42
+ <% end %>
43
+
44
+ <% if payment.line_items.any? %>
45
+ <_1:invoice>
46
+ <!-- TODO: include VAT options -->
47
+ <_1:totalNetAmount currency="<%= payment.currency %>"><%= payment.amount %></_1:totalNetAmount>
48
+ <!--1 to 1000 repetitions:-->
49
+ <% for vat_rate in payment.vat_rates %>
50
+ <% puts "Rate: #{vat_rate}" %>
51
+
52
+ <_1:totalVatAmount currency="<%= payment.currency %>" rate="<%= vat_rate[:rate].to_s %>"><%= vat_rate[:total].to_i.to_s %></_1:totalVatAmount>
53
+ <% end %>
54
+ <!--1 to 1000 repetitions:-->
55
+ <% payment.line_items.each_with_index do |line_item, i| %>
56
+ <_1:item number="<%= i+1 %>">
57
+ <_1:name><%= line_item.name %></_1:name>
58
+ <_1:code><%= line_item.code %></_1:code>
59
+ <_1:quantity unitOfMeasure="<%= line_item.unit_of_measure %>"><%= line_item.quantity %></_1:quantity>
60
+ <_1:description><%= line_item.description %></_1:description>
61
+
62
+ <% if line_item.image.present? %>
63
+ <_1:image><%= line_item.image %></_1:image>
64
+ <% end %>
65
+ <_1:netAmount currency="<%= payment.currency %>">20</_1:netAmount>
66
+ <_1:grossAmount currency="<%= payment.currency %>">20</_1:grossAmount>
67
+ <_1:vat rate="20">
68
+ <_1:amount currency="<%= payment.currency %>">20</_1:amount>
69
+ </_1:vat>
70
+ <_1:totalNetAmount currency="<%= payment.currency %>">20</_1:totalNetAmount>
71
+ <_1:totalGrossAmount currency="<%= payment.currency %>">20</_1:totalGrossAmount>
72
+ <_1:totalVat rate="20">
73
+ <_1:amount currency="20">20</_1:amount>
74
+ </_1:totalVat>
75
+
76
+ </_1:item>
77
+ <% end %>
78
+ <_1:shipTo>
79
+ <_1:name>
80
+ <_1:first><%= shopper.first_name %></_1:first>
81
+ <_1:last><%= shopper.first_name %></_1:last>
82
+ </_1:name>
83
+ <_1:address>
84
+ <_1:street><%= shopper.street %></_1:street>
85
+ <_1:houseNumber><%= shopper.house_number %></_1:houseNumber>
86
+ <_1:postalCode><%= shopper.postal_code %></_1:postalCode>
87
+ <_1:city><%= shopper.city %></_1:city>
88
+ <_1:country code="<%= shopper.country_code %>"/>
89
+ </_1:address>
90
+ </_1:shipTo>
91
+ <!--Optional:-->
92
+ <_1:additionalDescription>sdf</_1:additionalDescription>
93
+ </_1:invoice>
94
+ <% end %>
95
+
96
+ </_1:createRequest>
97
+ </soapenv:Body>
98
+ </soapenv:Envelope>
@@ -0,0 +1,67 @@
1
+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:_1="http://www.docdatapayments.com/services/paymentservice/1_1/">
2
+ <soapenv:Header/>
3
+ <soapenv:Body>
4
+ <_1:startRequest version="1.1">
5
+ <_1:merchant name="<%= Docdata.username %>" password="<%= Docdata.password %>"/>
6
+ <_1:paymentOrderKey>?</_1:paymentOrderKey>
7
+ <!--You have a CHOICE of the next 2 items at this level-->
8
+ <!--Optional:-->
9
+ <_1:payment>
10
+ <_1:paymentMethod><%= payment.key %></_1:paymentMethod>
11
+ <!--Optional:-->
12
+ <_1:paymentAmount currency="?">?</_1:paymentAmount>
13
+ <!--You have a CHOICE of the next 6 items at this level-->
14
+ <!--Optional:-->
15
+ <_1:amexPaymentInput>
16
+ <_1:creditCardNumber>?</_1:creditCardNumber>
17
+ <_1:expiryDate>?</_1:expiryDate>
18
+ <_1:cid>?</_1:cid>
19
+ <_1:cardHolder>?</_1:cardHolder>
20
+ <_1:emailAddress>?</_1:emailAddress>
21
+ </_1:amexPaymentInput>
22
+ <!--Optional:-->
23
+ <_1:masterCardPaymentInput>
24
+ <_1:creditCardNumber>?</_1:creditCardNumber>
25
+ <_1:expiryDate>?</_1:expiryDate>
26
+ <_1:cvc2>?</_1:cvc2>
27
+ <_1:cardHolder>?</_1:cardHolder>
28
+ <_1:emailAddress>?</_1:emailAddress>
29
+ </_1:masterCardPaymentInput>
30
+ <!--Optional:-->
31
+ <_1:visaPaymentInput>
32
+ <_1:creditCardNumber>?</_1:creditCardNumber>
33
+ <_1:expiryDate>?</_1:expiryDate>
34
+ <_1:cvv2>?</_1:cvv2>
35
+ <_1:cardHolder>?</_1:cardHolder>
36
+ <_1:emailAddress>?</_1:emailAddress>
37
+ </_1:visaPaymentInput>
38
+ <!--Optional:-->
39
+ <_1:directDebitPaymentInput>
40
+ <_1:holderName>?</_1:holderName>
41
+ <_1:holderCity>?</_1:holderCity>
42
+ <_1:holderCountry code="?"/>
43
+ <_1:bic>?</_1:bic>
44
+ <_1:iban>?</_1:iban>
45
+ </_1:directDebitPaymentInput>
46
+ <!--Optional:-->
47
+ <_1:bankTransferPaymentInput>
48
+ <_1:emailAddress>?</_1:emailAddress>
49
+ </_1:bankTransferPaymentInput>
50
+ <!--Optional:-->
51
+ <_1:elvPaymentInput>
52
+ <_1:accountNumber>?</_1:accountNumber>
53
+ <_1:bankCode>?</_1:bankCode>
54
+ </_1:elvPaymentInput>
55
+ </_1:payment>
56
+ <!--Optional:-->
57
+ <_1:recurringPaymentRequest>
58
+ <_1:initialPaymentReference>
59
+ <!--You have a CHOICE of the next 3 items at this level-->
60
+ <_1:linkId>?</_1:linkId>
61
+ <_1:paymentId>?</_1:paymentId>
62
+ <_1:merchantReference>?</_1:merchantReference>
63
+ </_1:initialPaymentReference>
64
+ </_1:recurringPaymentRequest>
65
+ </_1:startRequest>
66
+ </soapenv:Body>
67
+ </soapenv:Envelope>
@@ -0,0 +1,9 @@
1
+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:_1="http://www.docdatapayments.com/services/paymentservice/1_1/">
2
+ <soapenv:Header/>
3
+ <soapenv:Body>
4
+ <_1:statusRequest version="1.1">
5
+ <_1:merchant name="<%=Docdata.username%>" password="<%= Docdata.password %>"/>
6
+ <_1:paymentOrderKey><%= payment.key %></_1:paymentOrderKey>
7
+ </_1:statusRequest>
8
+ </soapenv:Body>
9
+ </soapenv:Envelope>
@@ -0,0 +1,140 @@
1
+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:_1="http://www.docdatapayments.com/services/paymentservice/1_1/">
2
+ <soapenv:Header/>
3
+ <soapenv:Body>
4
+ <_1:createRequest version="1.1">
5
+ <_1:merchant name="?" password="?"/>
6
+ <_1:merchantOrderReference>?</_1:merchantOrderReference>
7
+ <_1:paymentPreferences>
8
+ <_1:profile>?</_1:profile>
9
+ <_1:numberOfDaysToPay>?</_1:numberOfDaysToPay>
10
+ <!--Optional:-->
11
+ <_1:exhortation>
12
+ <_1:period1 numberOfDays="?" profile="?"/>
13
+ <!--Optional:-->
14
+ <_1:period2 numberOfDays="?" profile="?"/>
15
+ </_1:exhortation>
16
+ </_1:paymentPreferences>
17
+ <!--Optional:-->
18
+ <_1:menuPreferences>
19
+ <!--Optional:-->
20
+ <_1:css id="?"/>
21
+ </_1:menuPreferences>
22
+ <_1:shopper id="?">
23
+ <_1:name>
24
+ <!--Optional:-->
25
+ <_1:prefix>?</_1:prefix>
26
+ <!--Optional:-->
27
+ <_1:initials>?</_1:initials>
28
+ <_1:first>?</_1:first>
29
+ <!--Optional:-->
30
+ <_1:middle>?</_1:middle>
31
+ <_1:last>?</_1:last>
32
+ <!--Optional:-->
33
+ <_1:suffix>?</_1:suffix>
34
+ </_1:name>
35
+ <_1:email>?</_1:email>
36
+ <_1:language code="?"/>
37
+ <_1:gender>?</_1:gender>
38
+ <!--Optional:-->
39
+ <_1:dateOfBirth>?</_1:dateOfBirth>
40
+ <!--Optional:-->
41
+ <_1:phoneNumber>?</_1:phoneNumber>
42
+ <!--Optional:-->
43
+ <_1:mobilePhoneNumber>?</_1:mobilePhoneNumber>
44
+ </_1:shopper>
45
+ <_1:totalGrossAmount currency="?">?</_1:totalGrossAmount>
46
+ <_1:billTo>
47
+ <_1:name>
48
+ <!--Optional:-->
49
+ <_1:prefix>?</_1:prefix>
50
+ <!--Optional:-->
51
+ <_1:initials>?</_1:initials>
52
+ <_1:first>?</_1:first>
53
+ <!--Optional:-->
54
+ <_1:middle>?</_1:middle>
55
+ <_1:last>?</_1:last>
56
+ <!--Optional:-->
57
+ <_1:suffix>?</_1:suffix>
58
+ </_1:name>
59
+ <_1:address>
60
+ <!--Optional:-->
61
+ <_1:company>?</_1:company>
62
+ <_1:street>?</_1:street>
63
+ <_1:houseNumber>?</_1:houseNumber>
64
+ <!--Optional:-->
65
+ <_1:houseNumberAddition>?</_1:houseNumberAddition>
66
+ <_1:postalCode>?</_1:postalCode>
67
+ <_1:city>?</_1:city>
68
+ <_1:country code="?"/>
69
+ </_1:address>
70
+ </_1:billTo>
71
+ <!--Optional:-->
72
+ <_1:description>?</_1:description>
73
+ <!--Optional:-->
74
+ <_1:receiptText>?</_1:receiptText>
75
+ <!--Optional:-->
76
+ <_1:includeCosts>false</_1:includeCosts>
77
+ <!--Optional:-->
78
+ <_1:paymentRequest>
79
+ <_1:initialPaymentReference>
80
+ <!--You have a CHOICE of the next 3 items at this level-->
81
+ <_1:linkId>?</_1:linkId>
82
+ <_1:paymentId>?</_1:paymentId>
83
+ <_1:merchantReference>?</_1:merchantReference>
84
+ </_1:initialPaymentReference>
85
+ </_1:paymentRequest>
86
+ <!--Optional:-->
87
+ <_1:invoice>
88
+ <_1:totalNetAmount currency="?">?</_1:totalNetAmount>
89
+ <!--1 to 1000 repetitions:-->
90
+ <_1:totalVatAmount currency="?" rate="?">?</_1:totalVatAmount>
91
+ <!--1 to 1000 repetitions:-->
92
+ <_1:item number="?">
93
+ <_1:name>?</_1:name>
94
+ <_1:code>?</_1:code>
95
+ <_1:quantity unitOfMeasure="?">?</_1:quantity>
96
+ <_1:description>?</_1:description>
97
+ <!--Optional:-->
98
+ <_1:image>?</_1:image>
99
+ <_1:netAmount currency="?">?</_1:netAmount>
100
+ <_1:grossAmount currency="?">?</_1:grossAmount>
101
+ <_1:vat rate="?">
102
+ <_1:amount currency="?">?</_1:amount>
103
+ </_1:vat>
104
+ <_1:totalNetAmount currency="?">?</_1:totalNetAmount>
105
+ <_1:totalGrossAmount currency="?">?</_1:totalGrossAmount>
106
+ <_1:totalVat rate="?">
107
+ <_1:amount currency="?">?</_1:amount>
108
+ </_1:totalVat>
109
+ </_1:item>
110
+ <_1:shipTo>
111
+ <_1:name>
112
+ <!--Optional:-->
113
+ <_1:prefix>?</_1:prefix>
114
+ <!--Optional:-->
115
+ <_1:initials>?</_1:initials>
116
+ <_1:first>?</_1:first>
117
+ <!--Optional:-->
118
+ <_1:middle>?</_1:middle>
119
+ <_1:last>?</_1:last>
120
+ <!--Optional:-->
121
+ <_1:suffix>?</_1:suffix>
122
+ </_1:name>
123
+ <_1:address>
124
+ <!--Optional:-->
125
+ <_1:company>?</_1:company>
126
+ <_1:street>?</_1:street>
127
+ <_1:houseNumber>?</_1:houseNumber>
128
+ <!--Optional:-->
129
+ <_1:houseNumberAddition>?</_1:houseNumberAddition>
130
+ <_1:postalCode>?</_1:postalCode>
131
+ <_1:city>?</_1:city>
132
+ <_1:country code="?"/>
133
+ </_1:address>
134
+ </_1:shipTo>
135
+ <!--Optional:-->
136
+ <_1:additionalDescription>?</_1:additionalDescription>
137
+ </_1:invoice>
138
+ </_1:createRequest>
139
+ </soapenv:Body>
140
+ </soapenv:Envelope>