activepayment 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .idea
6
+
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm --create use 1.9.2-p180
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in activepayment.gemspec
4
+ gemspec
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ == Supported Gateways
2
+
3
+ * {Wirecard}[http://www.wirecard.com] - DE
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "activepayment/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "activepayment"
7
+ s.version = ActivePayment::VERSION
8
+ s.authors = ["Alexander Klaiber"]
9
+ s.email = ["alex.klaiber@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = "CreditCard transactions framework"
12
+ s.description = "ActivePayment is an abstraction layer for different Payment-Interfaces (XML, JSON)"
13
+
14
+ s.rubyforge_project = "activepayment"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency 'activesupport'
22
+ s.add_dependency 'nokogiri'
23
+ s.add_dependency 'builder'
24
+ s.add_dependency 'money'
25
+ s.add_dependency 'uuid'
26
+
27
+ s.add_development_dependency 'rake'
28
+ s.add_development_dependency 'rspec'
29
+ s.add_development_dependency 'forgery'
30
+ end
@@ -0,0 +1,20 @@
1
+ module ActivePayment
2
+ class Railtie < Rails::Railtie
3
+
4
+ initializer "setup payment" do
5
+ config_file = Rails.root.join("config", "activepayment.yml")
6
+ if config_file.file?
7
+ ActivePayment::Wirecard::Gateway.config = YAML.load(ERB.new(config_file.read).result)[Rails.env]
8
+ end
9
+ end
10
+
11
+ initializer "warn when configuration is missing" do
12
+ config.after_initialize do
13
+ unless Rails.root.join("config", "activepayment.yml").file?
14
+ puts "\nActivePayment config not found. Create a config file at: config/activepayment.yml"
15
+ end
16
+ end
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,58 @@
1
+ module ActivePayment
2
+ class Response
3
+
4
+ def initialize(xml)
5
+ @doc = Nokogiri::XML(xml)
6
+ if @doc.at_css('WIRECARD_BXML').nil?
7
+ raise ActivePayment::Exception, "No valid response"
8
+ end
9
+ end
10
+
11
+ def to_s
12
+ @doc.to_s
13
+ end
14
+
15
+ def ok?
16
+ return_code.to_i.eql?(0)
17
+ end
18
+
19
+ def [](node_name)
20
+ parse(@doc.at_css(node_name).content)
21
+ end
22
+
23
+ def successful?
24
+ self.function_result.eql?('ACK') || self.function_result.eql?('PENDING')
25
+ end
26
+
27
+ def failed?
28
+ self.function_result.eql?('NOK')
29
+ end
30
+
31
+ public
32
+
33
+ def method_missing(method, *args)
34
+ node_name = method.to_node_name
35
+ unless node_name.blank?
36
+ node = @doc.at_css(node_name)
37
+ unless node.nil?
38
+ parse(@doc.at_css(node_name).content)
39
+ else
40
+ super
41
+ end
42
+ else
43
+ super
44
+ end
45
+ end
46
+
47
+ private
48
+
49
+ def parse(value)
50
+ begin
51
+ return Integer(value)
52
+ rescue
53
+ return value
54
+ end
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,3 @@
1
+ module ActivePayment
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,173 @@
1
+ module ActivePayment
2
+ module Wirecard
3
+ class Gateway
4
+
5
+ TEST_URL = 'https://c3-test.wirecard.com/secure/ssl-gateway'
6
+ LIVE_URL = 'https://c3.wirecard.com/secure/ssl-gateway'
7
+
8
+ attr_accessor :transaction_id, :amount, :transaction_params, :jop_id
9
+
10
+ class << self
11
+ attr_accessor :login, :password, :signature, :mode, :default_currency
12
+
13
+ def url
14
+ if self.mode.blank? || self.mode.eql?('demo')
15
+ TEST_URL
16
+ else
17
+ LIVE_URL
18
+ end
19
+ end
20
+ end
21
+
22
+ def initialize(transaction_id, amount)
23
+ @transaction_id = transaction_id
24
+ @amount = amount
25
+ end
26
+
27
+ def self.config=(config)
28
+ config = config["wirecard"] if config.include?("wirecard") && !config["wirecard"].blank?
29
+ config.each { |method, value| self.send("#{method}=", value) }
30
+ end
31
+
32
+ def self.config
33
+ yield self
34
+ end
35
+
36
+ public
37
+
38
+ def authorization(credit_card)
39
+ post_request(self.authorization_request(credit_card))
40
+ end
41
+
42
+ def authorization_request(credit_card)
43
+ build_request(:authorization) do |xml|
44
+ xml.tag! 'TransactionID', self.transaction_id
45
+ xml.tag! 'Currency', Gateway.default_currency
46
+ xml.tag! 'Amount', self.amount
47
+
48
+ add_optional_node(xml, :commerce_type)
49
+ add_optional_node(xml, :country_code)
50
+ add_optional_node(xml, :credit_card_data, credit_card)
51
+ add_optional_node(xml, :contact_data)
52
+ add_optional_node(xml, :corptrustcenter_data)
53
+ end
54
+ end
55
+
56
+ def capture_authorization(guwid)
57
+ post_request(self.capture_authorization_request(guwid))
58
+ end
59
+
60
+ def capture_authorization_request(guwid)
61
+ build_request(:capture_authorization) do |xml|
62
+ xml.tag! 'TransactionID', self.transaction_id
63
+ xml.tag! 'GuWID', guwid
64
+ xml.tag! 'Amount', self.amount
65
+
66
+ add_optional_node(xml, :country_code)
67
+ end
68
+ end
69
+
70
+ def purchase(credit_card, pares = nil, guwid = nil)
71
+ post_request(self.purchase_request(credit_card, pares, guwid))
72
+ end
73
+
74
+ def purchase_request(credit_card, pares = nil, guwid = nil)
75
+ build_request(:purchase) do |xml|
76
+ xml.tag! 'TransactionID', self.transaction_id
77
+ xml.tag! 'Currency', Gateway.default_currency
78
+ xml.tag! 'Amount', self.amount
79
+ xml.tag! 'GuWID', guwid unless guwid.blank?
80
+ xml.tag! 'THREE-D_SECURE' do
81
+ xml.tag! 'PARes', pares
82
+ end unless pares.blank?
83
+
84
+ add_optional_node(xml, :commerce_type)
85
+ add_optional_node(xml, :country_code)
86
+ add_optional_node(xml, :credit_card_data, credit_card)
87
+ end
88
+ end
89
+
90
+ def enrollment_check(credit_card)
91
+ post_request(self.enrollment_check_request(credit_card))
92
+ end
93
+
94
+ def enrollment_check_request(credit_card)
95
+ build_request(:enrollment_check) do |xml|
96
+ xml.tag! 'TransactionID', self.transaction_id
97
+ xml.tag! 'Currency', Gateway.default_currency
98
+ xml.tag! 'Amount', self.amount
99
+
100
+ add_optional_node(xml, :country_code)
101
+ add_optional_node(xml, :credit_card_data, credit_card)
102
+ end
103
+ end
104
+
105
+ private
106
+
107
+ def add_optional_node(xml, name, value = nil)
108
+ if value.blank? && self.transaction_params.include?(name) && !self.transaction_params[name].blank?
109
+ value = self.transaction_params[name]
110
+ end
111
+ unless value.blank?
112
+ if value.kind_of?(Hash)
113
+ xml.tag! name.to_s.upcase do
114
+ value.each do |node_name, node_value|
115
+ add_optional_node(xml, node_name, node_value)
116
+ end
117
+ end
118
+ else
119
+ xml.tag! name.to_node_name, value
120
+ end
121
+ end
122
+ end
123
+
124
+ def transaction_node(xml, &block)
125
+ options = {}
126
+ options[:mode] = Gateway.mode unless Gateway.mode.blank?
127
+ xml.tag! 'CC_TRANSACTION', options do
128
+ block.call(xml)
129
+ end
130
+ end
131
+
132
+ def build_request(method, &block)
133
+ xml = Builder::XmlMarkup.new :indent => 2
134
+ xml.instruct!
135
+ xml.tag! 'WIRECARD_BXML' do
136
+ xml.tag! 'W_REQUEST' do
137
+ xml.tag! 'W_JOB' do
138
+ xml.tag! 'JobID', self.jop_id
139
+ xml.tag! 'BusinessCaseSignature', Gateway.signature
140
+ xml.tag! "FNC_CC_#{method.to_s.upcase}" do
141
+ xml.tag! 'FunctionID', 'Test dummy FunctionID'
142
+ transaction_node(xml, &block)
143
+ end
144
+ end
145
+ end
146
+ end
147
+ xml.target!
148
+ end
149
+
150
+ def post_request(xml)
151
+ uri = URI.parse(Gateway.url)
152
+ unless uri.nil?
153
+ http = Net::HTTP.new(uri.host, 443)
154
+ if http
155
+ http.use_ssl = true
156
+ request = Net::HTTP::Post.new(uri.path)
157
+ if request
158
+ request.content_type = "text/xml"
159
+ request.content_length = xml.size
160
+ request.basic_auth(Gateway.login, Gateway.password)
161
+ request.body = xml
162
+ response = http.request(request)
163
+ if response
164
+ return Response.new(response.body)
165
+ end
166
+ end
167
+ end
168
+ end
169
+ end
170
+
171
+ end
172
+ end
173
+ end
@@ -0,0 +1,39 @@
1
+ require "bundler/setup"
2
+
3
+ require 'uri'
4
+ require 'net/http'
5
+ require 'net/https'
6
+
7
+ require "active_support/core_ext"
8
+ require "builder"
9
+ require "nokogiri"
10
+ require "money"
11
+ require "uuid"
12
+
13
+ require "activepayment/railtie" if defined?(Rails)
14
+ require "activepayment/version"
15
+ require "activepayment/response"
16
+ require "activepayment/wirecard/gateway"
17
+
18
+ module ActivePayment
19
+ class Exception < RuntimeError
20
+ end
21
+
22
+ Symbol.class_eval do
23
+ define_method :to_node_name do
24
+ case self
25
+ when :ip_address
26
+ return 'IPAddress'
27
+ when :address_1
28
+ return 'Address1'
29
+ when :address_2
30
+ return 'Address2'
31
+ end
32
+ if self.to_s.match('[0-9]')
33
+ self.to_s.upcase
34
+ else
35
+ self.to_s.camelize.gsub('Id', 'ID')
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,10 @@
1
+ development:
2
+ wirecard:
3
+ login: 56504
4
+ password: TestXAPTERR
5
+ signature: 56504
6
+
7
+ test:
8
+
9
+ production:
10
+
@@ -0,0 +1,26 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <WIRECARD_BXML>
3
+ <W_REQUEST>
4
+ <W_JOB>
5
+ <JobID>test dummy data</JobID>
6
+ <BusinessCaseSignature>56501</BusinessCaseSignature>
7
+ <FNC_CC_AUTHORIZATION>
8
+ <FunctionID>Test dummy FunctionID</FunctionID>
9
+ <CC_TRANSACTION mode="demo">
10
+ <TransactionID>123</TransactionID>
11
+ <Currency>EUR</Currency>
12
+ <Amount>100</Amount>
13
+ <CommerceType>eCommerce</CommerceType>
14
+ <CountryCode>DE</CountryCode>
15
+ <CREDIT_CARD_DATA>
16
+ <CreditCardNumber>4200000000000000</CreditCardNumber>
17
+ <CVC2>001</CVC2>
18
+ <ExpirationYear>2009</ExpirationYear>
19
+ <ExpirationMonth>01</ExpirationMonth>
20
+ <CardHolderName>John Doe</CardHolderName>
21
+ </CREDIT_CARD_DATA>
22
+ </CC_TRANSACTION>
23
+ </FNC_CC_AUTHORIZATION>
24
+ </W_JOB>
25
+ </W_REQUEST>
26
+ </WIRECARD_BXML>
@@ -0,0 +1,43 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <WIRECARD_BXML>
3
+ <W_REQUEST>
4
+ <W_JOB>
5
+ <JobID>test dummy data</JobID>
6
+ <BusinessCaseSignature>56501</BusinessCaseSignature>
7
+ <FNC_CC_AUTHORIZATION>
8
+ <FunctionID>Test dummy FunctionID</FunctionID>
9
+ <CC_TRANSACTION mode="demo">
10
+ <TransactionID>123</TransactionID>
11
+ <Currency>EUR</Currency>
12
+ <Amount>100</Amount>
13
+ <CommerceType>eCommerce</CommerceType>
14
+ <CountryCode>DE</CountryCode>
15
+ <CREDIT_CARD_DATA>
16
+ <CreditCardNumber>4200000000000000</CreditCardNumber>
17
+ <CVC2>001</CVC2>
18
+ <ExpirationYear>2009</ExpirationYear>
19
+ <ExpirationMonth>01</ExpirationMonth>
20
+ <CardHolderName>John Doe</CardHolderName>
21
+ </CREDIT_CARD_DATA>
22
+ <CONTACT_DATA>
23
+ <IPAddress>192.168.1.1</IPAddress>
24
+ </CONTACT_DATA>
25
+ <CORPTRUSTCENTER_DATA>
26
+ <ADDRESS>
27
+ <FirstName>John</FirstName>
28
+ <LastName>Doe</LastName>
29
+ <Address1>550 South Winchester blvd.</Address1>
30
+ <Address2>P.O. Box 850</Address2>
31
+ <City>San Jose</City>
32
+ <ZipCode>95128</ZipCode>
33
+ <State>CA</State>
34
+ <Country>US</Country>
35
+ <Phone>+1(202)555-1234</Phone>
36
+ <Email>John.Doe@email.com</Email>
37
+ </ADDRESS>
38
+ </CORPTRUSTCENTER_DATA>
39
+ </CC_TRANSACTION>
40
+ </FNC_CC_AUTHORIZATION>
41
+ </W_JOB>
42
+ </W_REQUEST>
43
+ </WIRECARD_BXML>
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <WIRECARD_BXML>
3
+ <W_REQUEST>
4
+ <W_JOB>
5
+ <JobID>test dummy data</JobID>
6
+ <BusinessCaseSignature>56501</BusinessCaseSignature>
7
+ <FNC_CC_CAPTURE_AUTHORIZATION>
8
+ <FunctionID>Test dummy FunctionID</FunctionID>
9
+ <CC_TRANSACTION mode="demo">
10
+ <TransactionID>123</TransactionID>
11
+ <GuWID>C822580121385121429927</GuWID>
12
+ <Amount>100</Amount>
13
+ <CountryCode>DE</CountryCode>
14
+ </CC_TRANSACTION>
15
+ </FNC_CC_CAPTURE_AUTHORIZATION>
16
+ </W_JOB>
17
+ </W_REQUEST>
18
+ </WIRECARD_BXML>
@@ -0,0 +1,25 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <WIRECARD_BXML>
3
+ <W_REQUEST>
4
+ <W_JOB>
5
+ <JobID>test dummy data</JobID>
6
+ <BusinessCaseSignature>56501</BusinessCaseSignature>
7
+ <FNC_CC_ENROLLMENT_CHECK>
8
+ <FunctionID>Test dummy FunctionID</FunctionID>
9
+ <CC_TRANSACTION mode="demo">
10
+ <TransactionID>123</TransactionID>
11
+ <Currency>EUR</Currency>
12
+ <Amount>100</Amount>
13
+ <CountryCode>DE</CountryCode>
14
+ <CREDIT_CARD_DATA>
15
+ <CreditCardNumber>4200000000000000</CreditCardNumber>
16
+ <CVC2>001</CVC2>
17
+ <ExpirationYear>2009</ExpirationYear>
18
+ <ExpirationMonth>01</ExpirationMonth>
19
+ <CardHolderName>John Doe</CardHolderName>
20
+ </CREDIT_CARD_DATA>
21
+ </CC_TRANSACTION>
22
+ </FNC_CC_ENROLLMENT_CHECK>
23
+ </W_JOB>
24
+ </W_REQUEST>
25
+ </WIRECARD_BXML>
@@ -0,0 +1,26 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <WIRECARD_BXML>
3
+ <W_REQUEST>
4
+ <W_JOB>
5
+ <JobID>test dummy data</JobID>
6
+ <BusinessCaseSignature>56501</BusinessCaseSignature>
7
+ <FNC_CC_PURCHASE>
8
+ <FunctionID>Test dummy FunctionID</FunctionID>
9
+ <CC_TRANSACTION mode="demo">
10
+ <TransactionID>123</TransactionID>
11
+ <Currency>EUR</Currency>
12
+ <Amount>100</Amount>
13
+ <CommerceType>eCommerce</CommerceType>
14
+ <CountryCode>DE</CountryCode>
15
+ <CREDIT_CARD_DATA>
16
+ <CreditCardNumber>4200000000000000</CreditCardNumber>
17
+ <CVC2>001</CVC2>
18
+ <ExpirationYear>2009</ExpirationYear>
19
+ <ExpirationMonth>01</ExpirationMonth>
20
+ <CardHolderName>John Doe</CardHolderName>
21
+ </CREDIT_CARD_DATA>
22
+ </CC_TRANSACTION>
23
+ </FNC_CC_PURCHASE>
24
+ </W_JOB>
25
+ </W_REQUEST>
26
+ </WIRECARD_BXML>
@@ -0,0 +1,30 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <WIRECARD_BXML>
3
+ <W_REQUEST>
4
+ <W_JOB>
5
+ <JobID>test dummy data</JobID>
6
+ <BusinessCaseSignature>56501</BusinessCaseSignature>
7
+ <FNC_CC_PURCHASE>
8
+ <FunctionID>Test dummy FunctionID</FunctionID>
9
+ <CC_TRANSACTION mode="demo">
10
+ <TransactionID>123</TransactionID>
11
+ <Currency>EUR</Currency>
12
+ <Amount>100</Amount>
13
+ <GuWID>C822580121385121429927</GuWID>
14
+ <THREE-D_SECURE>
15
+ <PARes>123</PARes>
16
+ </THREE-D_SECURE>
17
+ <CommerceType>eCommerce</CommerceType>
18
+ <CountryCode>DE</CountryCode>
19
+ <CREDIT_CARD_DATA>
20
+ <CreditCardNumber>4200000000000000</CreditCardNumber>
21
+ <CVC2>001</CVC2>
22
+ <ExpirationYear>2009</ExpirationYear>
23
+ <ExpirationMonth>01</ExpirationMonth>
24
+ <CardHolderName>John Doe</CardHolderName>
25
+ </CREDIT_CARD_DATA>
26
+ </CC_TRANSACTION>
27
+ </FNC_CC_PURCHASE>
28
+ </W_JOB>
29
+ </W_REQUEST>
30
+ </WIRECARD_BXML>
@@ -0,0 +1,24 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <WIRECARD_BXML xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xsi:noNamespaceSchemaLocation="wirecard.xsd">
3
+ <W_RESPONSE>
4
+ <W_JOB>
5
+ <JobID>test dummy data</JobID>
6
+ <FNC_CC_AUTHORIZATION>
7
+ <FunctionID>Wirecard remote test purchase</FunctionID>
8
+ <CC_TRANSACTION>
9
+ <TransactionID>1</TransactionID>
10
+ <PROCESSING_STATUS>
11
+ <GuWID>C822580121385121429927</GuWID>
12
+ <AuthorizationCode>709678</AuthorizationCode>
13
+ <Info>THIS IS A DEMO TRANSACTION USING CREDIT CARD NUMBER 420000****0000. NO REAL MONEY WILL BE
14
+ TRANSFERED.
15
+ </Info>
16
+ <StatusType>INFO</StatusType>
17
+ <FunctionResult>ACK</FunctionResult>
18
+ <TimeStamp>2008-06-19 06:53:33</TimeStamp>
19
+ </PROCESSING_STATUS>
20
+ </CC_TRANSACTION>
21
+ </FNC_CC_AUTHORIZATION>
22
+ </W_JOB>
23
+ </W_RESPONSE>
24
+ </WIRECARD_BXML>
@@ -0,0 +1,24 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <WIRECARD_BXML xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xsi:noNamespaceSchemaLocation="wirecard.xsd">
3
+ <W_RESPONSE>
4
+ <W_JOB>
5
+ <JobID>test dummy data</JobID>
6
+ <FNC_CC_CAPTURE_AUTHORIZATION>
7
+ <FunctionID>Wirecard remote test purchase</FunctionID>
8
+ <CC_TRANSACTION>
9
+ <TransactionID>1</TransactionID>
10
+ <PROCESSING_STATUS>
11
+ <GuWID>C833707121385268439116</GuWID>
12
+ <AuthorizationCode>915025</AuthorizationCode>
13
+ <Info>THIS IS A DEMO TRANSACTION USING CREDIT CARD NUMBER 420000****0000. NO REAL MONEY WILL BE
14
+ TRANSFERED.
15
+ </Info>
16
+ <StatusType>INFO</StatusType>
17
+ <FunctionResult>ACK</FunctionResult>
18
+ <TimeStamp>2008-06-19 07:18:04</TimeStamp>
19
+ </PROCESSING_STATUS>
20
+ </CC_TRANSACTION>
21
+ </FNC_CC_CAPTURE_AUTHORIZATION>
22
+ </W_JOB>
23
+ </W_RESPONSE>
24
+ </WIRECARD_BXML>
@@ -0,0 +1,117 @@
1
+ require "spec_helper"
2
+
3
+ describe ActivePayment::Wirecard::Gateway do
4
+
5
+ let(:amount) { 100 }
6
+ let(:gateway) { ActivePayment::Wirecard::Gateway.new(123, amount) }
7
+
8
+ describe "post request" do
9
+
10
+ before(:all) do
11
+ ActivePayment::Wirecard::Gateway.login = 56501
12
+ ActivePayment::Wirecard::Gateway.password = "TestXAPTER"
13
+ ActivePayment::Wirecard::Gateway.signature = "56501"
14
+ ActivePayment::Wirecard::Gateway.mode = "demo"
15
+ ActivePayment::Wirecard::Gateway.default_currency = 'EUR'
16
+
17
+ gateway.jop_id = 'test dummy data'
18
+ gateway.transaction_params = {
19
+ :commerce_type => 'eCommerce',
20
+ :country_code => 'DE'
21
+ }
22
+ end
23
+
24
+ it "should post authorization request" do
25
+ response = gateway.authorization(credit_card_hash)
26
+
27
+ response.successful?.should be_true
28
+ response.info.should include('THIS IS A DEMO')
29
+ response.status_type.should eql('INFO')
30
+ response.authorization_code.should_not be_blank
31
+ response['GuWID'].should_not be_blank
32
+ end
33
+
34
+ it "should post capture_authorization request" do
35
+ guwid = gateway.authorization(credit_card_hash)['GuWID']
36
+ response = gateway.capture_authorization(guwid)
37
+
38
+ response.successful?.should be_true
39
+ response.info.should include('THIS IS A DEMO')
40
+ response.status_type.should eql('INFO')
41
+ response.authorization_code.should_not be_blank
42
+ response['GuWID'].should_not be_blank
43
+ end
44
+
45
+ it "should post purchase request" do
46
+ response = gateway.purchase(credit_card_hash)
47
+
48
+ response.successful?.should be_true
49
+ response.info.should include('THIS IS A DEMO')
50
+ response.status_type.should eql('INFO')
51
+ response.authorization_code.should_not be_blank
52
+ response['GuWID'].should_not be_blank
53
+ end
54
+
55
+ describe "with address" do
56
+ before(:all) do
57
+ gateway.transaction_params = {
58
+ :commerce_type => 'eCommerce',
59
+ :country_code => 'DE',
60
+ :contact_data => {:ip_address => '192.168.1.1'},
61
+ :corptrustcenter_data => {
62
+ :address => {
63
+ :first_name => Forgery::Name.first_name,
64
+ :last_name => Forgery::Name.last_name,
65
+ :address_1 => '550 South Winchester blvd.',
66
+ :address_2 => 'P.O. Box 850',
67
+ :city => 'San Jose',
68
+ :zip_code => '95128',
69
+ :state => 'CA',
70
+ :country => 'US',
71
+ :phone => '+1(202)555-1234',
72
+ :email => 'John.Doe@email.com'
73
+ }
74
+ }
75
+ }
76
+ end
77
+
78
+ it "should post authorization request with address" do
79
+ response = gateway.authorization(credit_card_hash)
80
+
81
+ response.successful?.should be_true
82
+ response.info.should include('THIS IS A DEMO')
83
+ response.status_type.should eql('INFO')
84
+ response.authorization_code.should_not be_blank
85
+ response['GuWID'].should_not be_blank
86
+ end
87
+ end
88
+ end
89
+
90
+ describe "3D secure" do
91
+
92
+ before(:all) do
93
+ ActivePayment::Wirecard::Gateway.login = '000000315DE09F66'
94
+ ActivePayment::Wirecard::Gateway.password = 'TestXAPTER'
95
+ ActivePayment::Wirecard::Gateway.signature = '000000315DE0A429'
96
+ ActivePayment::Wirecard::Gateway.mode = ''
97
+
98
+ gateway.jop_id = 'test dummy data'
99
+ gateway.transaction_params = {
100
+ :commerce_type => 'eCommerce',
101
+ :country_code => 'DE'
102
+ }
103
+ end
104
+
105
+ it "should enrollment_check is successfully" do
106
+ response = gateway.enrollment_check(credit_card_hash('4012000300001003', :cvc2 => '003'))
107
+
108
+ response.successful?.should be_true
109
+ response.status_type.should eql('Y')
110
+ response['GuWID'].should_not be_blank
111
+ response['PAReq'].should_not be_blank
112
+ response['AcsUrl'].should_not be_blank
113
+ end
114
+
115
+ end
116
+
117
+ end
@@ -0,0 +1,22 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
3
+
4
+ require "activepayment"
5
+ require "rspec"
6
+ require "forgery"
7
+
8
+ FIXTURES_PATH = "#{File.dirname(__FILE__)}/fixtures"
9
+
10
+ RSpec.configure do |config|
11
+ config.mock_framework = :rspec
12
+ end
13
+
14
+ def credit_card_hash(number = '4200000000000000', options = {})
15
+ {
16
+ :credit_card_number => number,
17
+ :cvc2 => '001',
18
+ :expiration_year => Time.now.year + 1,
19
+ :expiration_month => '01',
20
+ :card_holder_name => Forgery::Name.full_name
21
+ }.update(options)
22
+ end
@@ -0,0 +1,12 @@
1
+ require "spec_helper"
2
+
3
+ describe ActivePayment::Response do
4
+
5
+ it "should parse response" do
6
+ File.open("#{FIXTURES_PATH}/wirecard/gateway/successful_authorization_response.xml") do |file|
7
+ response = ActivePayment::Response.new(file)
8
+ response.job_id.should eql('test dummy data')
9
+ response['GuWID'].should eql('C822580121385121429927')
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,125 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActivePayment::Wirecard::Gateway do
4
+
5
+ let(:amount) { 100 }
6
+ let(:gateway) { ActivePayment::Wirecard::Gateway.new(123, amount) }
7
+ let(:guwid) { 'C822580121385121429927' }
8
+
9
+ before(:all) do
10
+ ActivePayment::Wirecard::Gateway.login = 56501
11
+ ActivePayment::Wirecard::Gateway.password = "TestXAPTER"
12
+ ActivePayment::Wirecard::Gateway.signature = "56501"
13
+ ActivePayment::Wirecard::Gateway.mode = "demo"
14
+ ActivePayment::Wirecard::Gateway.default_currency = 'EUR'
15
+
16
+ gateway.jop_id = 'test dummy data'
17
+ gateway.transaction_params = {
18
+ :commerce_type => 'eCommerce',
19
+ :country_code => 'DE'
20
+ }
21
+ end
22
+
23
+ it "should build authorization request" do
24
+ File.open("#{FIXTURES_PATH}/wirecard/gateway/authorization_request.xml") do |xml_file|
25
+ gateway.authorization_request(credit_card_hash('4200000000000000', :expiration_year => 2009, :card_holder_name => 'John Doe')).should eql(xml_file.read)
26
+ end
27
+ end
28
+
29
+ it "should build capture_authorization request" do
30
+ File.open("#{FIXTURES_PATH}/wirecard/gateway/capture_authorization_request.xml") do |xml_file|
31
+ gateway.capture_authorization_request(guwid).should eql(xml_file.read)
32
+ end
33
+ end
34
+
35
+ it "should build purchase request" do
36
+ File.open("#{FIXTURES_PATH}/wirecard/gateway/purchase_request.xml") do |xml_file|
37
+ gateway.purchase_request(credit_card_hash('4200000000000000', :expiration_year => 2009, :card_holder_name => 'John Doe')).should eql(xml_file.read)
38
+ end
39
+ end
40
+
41
+ it "should build purchase request with 3d" do
42
+ File.open("#{FIXTURES_PATH}/wirecard/gateway/purchase_request_with_3d.xml") do |xml_file|
43
+ gateway.purchase_request(credit_card_hash('4200000000000000', :expiration_year => 2009, :card_holder_name => 'John Doe'), 123, 'C822580121385121429927').should eql(xml_file.read)
44
+ end
45
+ end
46
+
47
+ it "should build enrollment check request" do
48
+ File.open("#{FIXTURES_PATH}/wirecard/gateway/enrollment_check_request.xml") do |xml_file|
49
+ gateway.enrollment_check_request(credit_card_hash('4200000000000000', :expiration_year => 2009, :card_holder_name => 'John Doe')).should eql(xml_file.read)
50
+ end
51
+ end
52
+
53
+ describe "with address" do
54
+ before(:all) do
55
+ gateway.transaction_params = {
56
+ :commerce_type => 'eCommerce',
57
+ :country_code => 'DE',
58
+ :contact_data => {:ip_address => '192.168.1.1'},
59
+ :corptrustcenter_data => {
60
+ :address => {
61
+ :first_name => 'John',
62
+ :last_name => 'Doe',
63
+ :address_1 => '550 South Winchester blvd.',
64
+ :address_2 => 'P.O. Box 850',
65
+ :city => 'San Jose',
66
+ :zip_code => '95128',
67
+ :state => 'CA',
68
+ :country => 'US',
69
+ :phone => '+1(202)555-1234',
70
+ :email => 'John.Doe@email.com'
71
+ }
72
+ }
73
+ }
74
+ end
75
+
76
+ it "should build authorization request" do
77
+ File.open("#{FIXTURES_PATH}/wirecard/gateway/authorization_request_with_address.xml") do |xml_file|
78
+ gateway.authorization_request(credit_card_hash('4200000000000000', :expiration_year => 2009, :card_holder_name => 'John Doe')).should eql(xml_file.read)
79
+ end
80
+ end
81
+ end
82
+
83
+ describe "config" do
84
+ it 'should set by methods' do
85
+ ActivePayment::Wirecard::Gateway.login = 56501
86
+ ActivePayment::Wirecard::Gateway.password = "TestXAPTER"
87
+ ActivePayment::Wirecard::Gateway.signature = 56501
88
+
89
+ ActivePayment::Wirecard::Gateway.login.should eql(56501)
90
+ ActivePayment::Wirecard::Gateway.password.should eql("TestXAPTER")
91
+ ActivePayment::Wirecard::Gateway.signature.should eql(56501)
92
+ end
93
+
94
+ it 'should set by hash' do
95
+ ActivePayment::Wirecard::Gateway.config = {:login => 56502, :password => "TestXAPTERR", :signature => 56502}
96
+
97
+ ActivePayment::Wirecard::Gateway.login.should eql(56502)
98
+ ActivePayment::Wirecard::Gateway.password.should eql("TestXAPTERR")
99
+ ActivePayment::Wirecard::Gateway.signature.should eql(56502)
100
+ end
101
+
102
+ it 'should set by block' do
103
+ ActivePayment::Wirecard::Gateway.config do |c|
104
+ c.login = 56503
105
+ c.password = "TestXAPTERR"
106
+ c.signature = 56503
107
+ end
108
+
109
+ ActivePayment::Wirecard::Gateway.login.should eql(56503)
110
+ ActivePayment::Wirecard::Gateway.password.should eql("TestXAPTERR")
111
+ ActivePayment::Wirecard::Gateway.signature.should eql(56503)
112
+ end
113
+
114
+ it 'should set by yml' do
115
+ File.open("#{FIXTURES_PATH}/activepayment_config.yml") do |config_file|
116
+ ActivePayment::Wirecard::Gateway.config = YAML.load(config_file.read)['development']
117
+
118
+ ActivePayment::Wirecard::Gateway.login.should eql(56504)
119
+ ActivePayment::Wirecard::Gateway.password.should eql("TestXAPTERR")
120
+ ActivePayment::Wirecard::Gateway.signature.should eql(56504)
121
+ end
122
+ end
123
+ end
124
+
125
+ end
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activepayment
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alexander Klaiber
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-07-12 00:00:00.000000000 +02:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activesupport
17
+ requirement: &6839600 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *6839600
26
+ - !ruby/object:Gem::Dependency
27
+ name: nokogiri
28
+ requirement: &6839180 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *6839180
37
+ - !ruby/object:Gem::Dependency
38
+ name: builder
39
+ requirement: &6838760 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :runtime
46
+ prerelease: false
47
+ version_requirements: *6838760
48
+ - !ruby/object:Gem::Dependency
49
+ name: money
50
+ requirement: &6838300 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ type: :runtime
57
+ prerelease: false
58
+ version_requirements: *6838300
59
+ - !ruby/object:Gem::Dependency
60
+ name: uuid
61
+ requirement: &6837880 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ type: :runtime
68
+ prerelease: false
69
+ version_requirements: *6837880
70
+ - !ruby/object:Gem::Dependency
71
+ name: rake
72
+ requirement: &6834880 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: *6834880
81
+ - !ruby/object:Gem::Dependency
82
+ name: rspec
83
+ requirement: &6834460 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: *6834460
92
+ - !ruby/object:Gem::Dependency
93
+ name: forgery
94
+ requirement: &6834040 !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ type: :development
101
+ prerelease: false
102
+ version_requirements: *6834040
103
+ description: ActivePayment is an abstraction layer for different Payment-Interfaces
104
+ (XML, JSON)
105
+ email:
106
+ - alex.klaiber@gmail.com
107
+ executables: []
108
+ extensions: []
109
+ extra_rdoc_files: []
110
+ files:
111
+ - .gitignore
112
+ - .rspec
113
+ - .rvmrc
114
+ - Gemfile
115
+ - README.rdoc
116
+ - Rakefile
117
+ - activepayment.gemspec
118
+ - lib/activepayment.rb
119
+ - lib/activepayment/railtie.rb
120
+ - lib/activepayment/response.rb
121
+ - lib/activepayment/version.rb
122
+ - lib/activepayment/wirecard/gateway.rb
123
+ - spec/fixtures/activepayment_config.yml
124
+ - spec/fixtures/wirecard/gateway/authorization_request.xml
125
+ - spec/fixtures/wirecard/gateway/authorization_request_with_address.xml
126
+ - spec/fixtures/wirecard/gateway/capture_authorization_request.xml
127
+ - spec/fixtures/wirecard/gateway/enrollment_check_request.xml
128
+ - spec/fixtures/wirecard/gateway/purchase_request.xml
129
+ - spec/fixtures/wirecard/gateway/purchase_request_with_3d.xml
130
+ - spec/fixtures/wirecard/gateway/successful_authorization_response.xml
131
+ - spec/fixtures/wirecard/gateway/successful_capture_response.xml
132
+ - spec/functional/wirecard_spec.rb
133
+ - spec/spec_helper.rb
134
+ - spec/unit/response_spec.rb
135
+ - spec/unit/wirecard/gateway_spec.rb
136
+ has_rdoc: true
137
+ homepage: ''
138
+ licenses: []
139
+ post_install_message:
140
+ rdoc_options: []
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ none: false
145
+ requirements:
146
+ - - ! '>='
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ none: false
151
+ requirements:
152
+ - - ! '>='
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ requirements: []
156
+ rubyforge_project: activepayment
157
+ rubygems_version: 1.6.2
158
+ signing_key:
159
+ specification_version: 3
160
+ summary: CreditCard transactions framework
161
+ test_files: []