datatrans 1.0.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.rvmrc +1 -0
- data/README.markdown +153 -9
- data/datatrans.gemspec +5 -0
- data/lib/datatrans.rb +9 -3
- data/lib/datatrans/common.rb +9 -0
- data/lib/datatrans/version.rb +1 -1
- data/lib/datatrans/web/transaction.rb +55 -0
- data/lib/datatrans/web/transaction/authorize.rb +68 -0
- data/lib/datatrans/xml/transaction.rb +47 -0
- data/lib/datatrans/xml/transaction/authorize.rb +83 -0
- data/lib/datatrans/xml/transaction/capture.rb +68 -0
- data/lib/datatrans/xml/transaction/request.rb +39 -0
- data/lib/datatrans/xml/transaction/response.rb +13 -0
- data/lib/datatrans/xml/transaction/void.rb +69 -0
- data/spec/common_spec.rb +20 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/web/authorize_spec.rb +128 -0
- data/spec/xml/authorizate_spec.rb +114 -0
- data/spec/xml/capture_spec.rb +103 -0
- data/spec/xml/void_spec.rb +103 -0
- metadata +105 -47
- data/lib/datatrans/notification.rb +0 -81
- data/lib/datatrans/transaction.rb +0 -79
@@ -1,79 +0,0 @@
|
|
1
|
-
require 'httparty'
|
2
|
-
|
3
|
-
class Datatrans::Transaction
|
4
|
-
include HTTParty
|
5
|
-
|
6
|
-
attr_reader :params
|
7
|
-
|
8
|
-
def initialize(params)
|
9
|
-
@params = params.symbolize_keys
|
10
|
-
end
|
11
|
-
|
12
|
-
def authorize
|
13
|
-
@response = self.class.post(Datatrans.xml_authorize_url,
|
14
|
-
:headers => { 'Content-Type' => 'text/xml' },
|
15
|
-
:body => build_authorize_request.to_s).parsed_response
|
16
|
-
end
|
17
|
-
|
18
|
-
def capture
|
19
|
-
@response = self.class.post(Datatrans.xml_settlement_url,
|
20
|
-
:headers => { 'Content-Type' => 'text/xml' },
|
21
|
-
:body => build_capture_request.to_s).parsed_response
|
22
|
-
end
|
23
|
-
|
24
|
-
def void
|
25
|
-
@response = self.class.post(Datatrans.xml_settlement_url,
|
26
|
-
:headers => { 'Content-Type' => 'text/xml' },
|
27
|
-
:body => build_void_request.to_s).parsed_response
|
28
|
-
end
|
29
|
-
|
30
|
-
def success?
|
31
|
-
@response['paymentService']['body']['transaction']['response'].present? rescue false
|
32
|
-
end
|
33
|
-
|
34
|
-
def error?
|
35
|
-
@response['paymentService']['body']['transaction']['error'].present? rescue false
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def build_xml_request(service)
|
41
|
-
xml = Builder::XmlMarkup.new
|
42
|
-
xml.instruct!
|
43
|
-
xml.tag! "#{service}Service", :version => 1 do
|
44
|
-
xml.body :merchantId => Datatrans.merchant_id do |body|
|
45
|
-
xml.transaction :refno => params[:refno] do
|
46
|
-
xml.request do
|
47
|
-
yield body
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
xml.target!
|
53
|
-
end
|
54
|
-
|
55
|
-
def build_authorize_request
|
56
|
-
build_xml_request(:authorization) do |xml|
|
57
|
-
xml.amount params[:amount]
|
58
|
-
xml.currency params[:currency]
|
59
|
-
xml.aliasCC params[:aliasCC]
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def build_capture_request
|
64
|
-
build_xml_request(:payment) do |xml|
|
65
|
-
xml.amount params[:amount]
|
66
|
-
xml.currency params[:currency]
|
67
|
-
xml.uppTransactionId params[:transaction_id]
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def build_void_request
|
72
|
-
build_xml_request(:payment) do |xml|
|
73
|
-
xml.amount params[:amount]
|
74
|
-
xml.currency params[:currency]
|
75
|
-
xml.uppTransactionId params[:transaction_id]
|
76
|
-
xml.reqtype 'DOA'
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|