payu_latam 0.0.1 → 0.1.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.
Files changed (4) hide show
  1. data/.gitignore +3 -0
  2. data/lib/payu.rb +83 -3
  3. data/lib/payu/version.rb +1 -1
  4. metadata +3 -2
@@ -0,0 +1,3 @@
1
+ Gemfile.lock
2
+ test.rb
3
+ *.gem
@@ -1,5 +1,85 @@
1
- require "payu/version"
1
+ require "json/add/core"
2
+ require "uri"
3
+ require "net/https"
4
+
5
+ class Payu
6
+ def initialize(api_key, api_login, test=false, lang="es")
7
+ @api_key = api_key
8
+ @api_login = api_login
9
+ @test = test
10
+ @lang = lang
11
+
12
+ @api_uri = URI.parse("https://#{'stg.' if test}api.payulatam.com")
13
+ @payments_api_url = "/payments-api/4.0/service.cgi"
14
+ @reports_api_url = "/reports-api/4.0/service.cgi"
15
+ end
16
+
17
+ #Reports API methods
18
+ def ping_reports
19
+ https_post(@reports_api_url, "PING")
20
+ end
21
+
22
+ def order_detail(order_id)
23
+ payload = { "details" => { "orderId" => order_id } }
24
+ https_post(@reports_api_url, "ORDER_DETAIL", payload)
25
+ end
26
+
27
+ def order_detail_by_reference_code(reference_code)
28
+ payload = { "details" => { "referenceCode" => reference_code } }
29
+ https_post(@reports_api_url, "ORDER_DETAIL_BY_REFERENCE_CODE", payload)
30
+ end
31
+
32
+ def transaction_response_detail(transaction_id)
33
+ payload = { "details" => { "transactionId" => transaction_id } }
34
+ https_post(@reports_api_url, "TRANSACTION_RESPONSE_DETAIL", payload)
35
+ end
36
+
37
+ #Payments API methods
38
+ def ping_payments
39
+ https_post(@payments_api_url, "PING")
40
+ end
41
+
42
+ def get_payment_methods
43
+ https_post(@payments_api_url, "GET_PAYMENT_METHODS")
44
+ end
45
+
46
+ def submit_transaction(payload)
47
+ https_post(@payments_api_url, "SUBMIT_TRANSACTION", payload)
48
+ end
49
+
50
+ private
51
+
52
+ def https_post(url, command, data={})
53
+ http = Net::HTTP.new(@api_uri.host, @api_uri.port)
54
+ http.use_ssl = true
55
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
56
+
57
+ data["merchant"] = {
58
+ "apiKey" => @api_key,
59
+ "apiLogin" => @api_login
60
+ }
61
+
62
+ data["command"] = command
63
+ data["test"] = @test
64
+ data["language"] = data["language"] || @lang
65
+
66
+ headers = {
67
+ "Accept" => "application/json",
68
+ "Content-Type" => "application/json; charset=utf-8"
69
+ }
70
+
71
+ result = http.send_request("POST", url, data.to_json, headers)
72
+
73
+ begin
74
+ response = JSON.parse(result.body)
75
+ rescue Exception => e
76
+ response = result.body
77
+ end
78
+
79
+ return {
80
+ "status" => result.code,
81
+ "response" => response
82
+ }
83
+ end
2
84
 
3
- module Payu
4
- # Your code goes here...
5
85
  end
@@ -1,3 +1,3 @@
1
1
  module Payu
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: payu_latam
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-24 00:00:00.000000000 Z
12
+ date: 2013-10-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -50,6 +50,7 @@ executables: []
50
50
  extensions: []
51
51
  extra_rdoc_files: []
52
52
  files:
53
+ - .gitignore
53
54
  - Gemfile
54
55
  - LICENSE.txt
55
56
  - README.md