veritrans 1.2.6 → 2.0.0beta

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 (73) hide show
  1. checksums.yaml +13 -5
  2. data/.gitignore +4 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +5 -0
  5. data/Gemfile.lock +111 -0
  6. data/README.md +258 -0
  7. data/Rakefile +7 -0
  8. data/api_reference.md +219 -0
  9. data/bin/veritrans +59 -48
  10. data/example/index.erb +118 -0
  11. data/example/response.erb +28 -0
  12. data/example/sinatra.rb +76 -0
  13. data/example/style.css +45 -0
  14. data/example/veritrans.yml +12 -0
  15. data/lib/generators/templates/assets/credit_card_form.js +50 -0
  16. data/lib/generators/templates/payments_controller.rb +81 -0
  17. data/lib/generators/templates/veritrans.rb +43 -0
  18. data/lib/generators/templates/veritrans.yml +13 -0
  19. data/lib/generators/templates/views/_credit_card_form.erb +42 -0
  20. data/lib/generators/templates/views/_veritrans_include.erb +10 -0
  21. data/lib/generators/templates/views/payments/create.erb +15 -0
  22. data/lib/generators/templates/views/payments/new.erb +6 -0
  23. data/lib/generators/veritrans/install_generator.rb +32 -0
  24. data/lib/generators/veritrans/payment_form_generator.rb +45 -0
  25. data/lib/veritrans/api.rb +90 -0
  26. data/lib/veritrans/cli.rb +166 -0
  27. data/lib/veritrans/client.rb +77 -209
  28. data/lib/veritrans/config.rb +48 -62
  29. data/lib/veritrans/events.rb +125 -0
  30. data/lib/veritrans/result.rb +81 -0
  31. data/lib/veritrans/version.rb +1 -41
  32. data/lib/veritrans.rb +79 -15
  33. data/license.txt +202 -0
  34. data/spec/cli_spec.rb +86 -0
  35. data/spec/configs/veritrans.yml +7 -0
  36. data/spec/configs/veritrans_flat.yml +2 -0
  37. data/spec/fixtures/approve_failed.yml +48 -0
  38. data/spec/fixtures/cancel_failed.yml +48 -0
  39. data/spec/fixtures/cancel_success.yml +106 -0
  40. data/spec/fixtures/capture_failed.yml +48 -0
  41. data/spec/fixtures/charge.yml +50 -0
  42. data/spec/fixtures/charge_direct.yml +56 -0
  43. data/spec/fixtures/charge_vtweb.yml +50 -0
  44. data/spec/fixtures/cli_test_1111-not-exists.yml +45 -0
  45. data/spec/fixtures/cli_test_not_exists.yml +45 -0
  46. data/spec/fixtures/cli_test_real_txn.yml +55 -0
  47. data/spec/fixtures/cli_test_unauthorized.yml +47 -0
  48. data/spec/fixtures/events_test_real_txn.yml +55 -0
  49. data/spec/fixtures/status_fail.yml +46 -0
  50. data/spec/fixtures/status_success.yml +109 -0
  51. data/spec/spec_helper.rb +29 -0
  52. data/spec/veritrans_client_spec.rb +83 -0
  53. data/spec/veritrans_config_spec.rb +48 -0
  54. data/spec/veritrans_events_spec.rb +70 -0
  55. data/spec/veritrans_logger_spec.rb +46 -0
  56. data/testing_webhooks.md +80 -0
  57. data/veritrans.gemspec +23 -0
  58. metadata +82 -31
  59. data/config/veritrans.yml +0 -24
  60. data/lib/generators/install_generator.rb +0 -78
  61. data/lib/generators/templates/app/controllers/vtlink/merchant_controller.rb +0 -7
  62. data/lib/generators/templates/app/controllers/vtlink/veritrans_controller.rb +0 -112
  63. data/lib/generators/templates/app/views/layouts/layout_auto_post.html.erb +0 -15
  64. data/lib/generators/templates/app/views/vtlink/merchant/checkout.html.erb +0 -43
  65. data/lib/generators/templates/app/views/vtlink/veritrans/cancel.html.erb +0 -2
  66. data/lib/generators/templates/app/views/vtlink/veritrans/confirm.html.erb +0 -13
  67. data/lib/generators/templates/app/views/vtlink/veritrans/error.html.erb +0 -2
  68. data/lib/generators/templates/app/views/vtlink/veritrans/finish.html.erb +0 -2
  69. data/lib/generators/templates/app/views/vtlink/veritrans/pay.html.erb +0 -2
  70. data/lib/generators/templates/config/veritrans.yml +0 -13
  71. data/lib/veritrans/hash_generator.rb +0 -19
  72. data/lib/veritrans/post_data.rb +0 -163
  73. data/lib/veritrans/v_t_direct.rb +0 -145
@@ -1,163 +0,0 @@
1
- # :nodoc:
2
- module Veritrans
3
-
4
- # hold information of "post data" need to pass when server need to get_keys
5
- module PostData
6
-
7
- # +:merchant_id,+
8
- # +:merchant_url,+
9
- # +:session_id,+
10
- # +:finish_payment_return_url,+
11
- # +:unfinish_payment_return_url,+
12
- # +:error_payment_return_url
13
- Merchant =[
14
- :merchant_id,
15
- :merchant_url,
16
- :finish_payment_return_url,
17
- :unfinish_payment_return_url,
18
- :error_payment_return_url
19
- ]
20
-
21
- # +:settlement_type,+
22
- # +:gross_amount,+
23
- # +:card_no,+
24
- # +:card_exp_date,+
25
- # +:customer_id,+
26
- # +:previous_customer_flag,+
27
- # +:customer_status,+
28
- Payment =[
29
- :settlement_type,
30
- :payment_type,
31
- :gross_amount,
32
- :card_no,
33
- :card_exp_date, # mm/yy
34
- :customer_id,
35
- :previous_customer_flag,
36
- :customer_status,
37
- # :installment,
38
- :installment_type,
39
- :installment_banks,
40
- :installment_terms,
41
- # :point,
42
- :point_banks,
43
- :payment_methods
44
- ]
45
-
46
- # +:first_name,+
47
- # +:last_name,+
48
- # +:address1,+
49
- # +:address2,+
50
- # +:city,+
51
- # +:country_code,+
52
- # +:postal_code,+
53
- # +:phone,+
54
- # +:email,+
55
- # customer_specification_flag,
56
- Personal =[
57
- :first_name,
58
- :last_name,
59
- :address1,
60
- :address2,
61
- :city,
62
- :country_code,
63
- :postal_code,
64
- :phone,
65
- :email,
66
- :customer_specification_flag # billing_address_different_with_shipping_address
67
- ]
68
-
69
- # +:shipping_flag,
70
- # +:shipping_first_name,
71
- # +:shipping_last_name,
72
- # +:shipping_address1,
73
- # +:shipping_address2,
74
- # +:shipping_city,
75
- # +:shipping_country_code,
76
- # +:shipping_postal_code,
77
- # +:shipping_phone,
78
- # +:shipping_method,
79
- Shipping =[
80
- :shipping_flag, # required_shipping_address
81
- :shipping_first_name,
82
- :shipping_last_name,
83
- :shipping_address1,
84
- :shipping_address2,
85
- :shipping_city,
86
- :shipping_country_code,
87
- :shipping_postal_code,
88
- :shipping_phone,
89
- :shipping_method,
90
- :shipping_email
91
- ]
92
-
93
- # +:lang_enable_flag,+
94
- # +:lang+
95
- Language =[
96
- :lang_enable_flag,
97
- :lang
98
- ]
99
-
100
- # +:repeat_line,+
101
- # +:purchases,+
102
- Purchases =[
103
- :repeat_line,
104
- :purchases
105
- ]
106
-
107
- # +:commodity_id,+
108
- # +:commodity_unit,+
109
- # +:commodity_num,+
110
- # +:commodity_name1,+
111
- # +:commodity_name2+
112
- PurchaseParam =[
113
- :commodity_id,
114
- :commodity_unit, # commodity_qty
115
- :commodity_num, # commodity_price
116
- :commodity_name1,
117
- :commodity_name2
118
- ]
119
-
120
- # AliasesParam = {
121
- # :commodity_unit => :commodity_qty,
122
- # :commodity_num => :commodity_price
123
- # }
124
-
125
- # +:order_id,+
126
- # +:session_id,+
127
- # +:merchanthash,+
128
- # +:card_capture_flag+
129
- OtherParam =[
130
- :order_id,
131
- :session_id,
132
- :merchanthash,
133
- :card_capture_flag,
134
- :promo_id,
135
- :promo_bins,
136
- :enable_3d_secure,
137
- :bank,
138
- :version
139
- ]
140
-
141
- # +:merchant_id,+
142
- # +:merchanthash,+
143
- # +:finish_payment_return_url,+
144
- # +:unfinish_payment_return_url,+
145
- # +:error_payment_return_url+
146
- ServerParam =[
147
- :merchant_id,
148
- :merchanthash,
149
- :finish_payment_return_url,
150
- :unfinish_payment_return_url,
151
- :error_payment_return_url
152
- ]
153
-
154
- # Params are the combination of this group:
155
- PostParam = (Merchant + Payment + Personal + Shipping + Language + Purchases + OtherParam) - ServerParam
156
- end
157
-
158
- # Sample of Array of purchase commodity
159
- # [
160
- # {"COMMODITY_ID" => "1233", "COMMODITY_UNIT" => "1", "COMMODITY_NUM" => "1", "COMMODITY_NAME1" => "BUKU", "COMMODITY_NAME2" => "BOOK"},
161
- # {"COMMODITY_ID" => "1243", "COMMODITY_UNIT" => "9", "COMMODITY_NUM" => "1", "COMMODITY_NAME1" => "BUKU Sembilan", "COMMODITY_NAME2" => "BOOK NINE"}
162
- # ]
163
- end
@@ -1,145 +0,0 @@
1
- require 'base64'
2
- require 'json'
3
- # :nodoc:
4
- module Veritrans
5
-
6
- # :nodoc:
7
- class VTDirect
8
- include Config
9
- @@attr = [:token_id, :order_id, :order_items, :gross_amount, :email, :shipping_address, :billing_address]
10
-
11
- # constructor to create instance of Veritrans::Client
12
- def initialize
13
- class <<self
14
- self
15
- end.class_eval do
16
- attr_accessor *@@attr
17
- end
18
- end
19
-
20
- # Example:
21
- #
22
- # vt_direct = Veritrans::VTDirect.new
23
- # vt_direct.token_id = "32eeeb9f-8ac3-b824-eb6d-faaa25240d27"
24
- # vt_direct.order_id = "order_5"
25
- # vt_direct.order_items = [
26
- # {
27
- # id: "10",
28
- # price: 100,
29
- # qty: 1,
30
- # name1: "Mie",
31
- # name2: "Goreng"
32
- # },
33
- # {
34
- # id: "11",
35
- # price: 100,
36
- # qty: 1,
37
- # name1: "Mie",
38
- # name2: "Kuah"
39
- # }
40
- # ]
41
- # vt_direct.gross_amount = 200
42
- # vt_direct.email = "echo.khannedy@gmail.com"
43
- # vt_direct.shipping_address = {
44
- # first_name: "Sam",
45
- # last_name: "Anthony",
46
- # address1: "Buaran I",
47
- # address2: "Pulogadung",
48
- # city: "Jakarta",
49
- # country_code: "IDN",
50
- # postal_code: "16954",
51
- # phone: "0123456789123"
52
- # }
53
- # vt_direct.billing_address = {
54
- # first_name: "Sam",
55
- # last_name: "Anthony",
56
- # address1: "Buaran I",
57
- # address2: "Pulogadung",
58
- # city: "Jakarta",
59
- # country_code: "IDN",
60
- # postal_code: "16954",
61
- # phone: "0123456789123"
62
- # }
63
- # vt_direct.charges
64
- #
65
- def charges
66
- parms = prepare_params(@@attr).to_json
67
- basic = Base64.encode64("#{server_key}:")
68
- copt = {:url => server_host}
69
- copt[:ssl] = { :ca_path => VTDirect.config["ca_path"] } if VTDirect.config["ca_path"] #"/usr/lib/ssl/certs"
70
- conn = Faraday.new( copt )
71
- @resp = conn.post do |req|
72
- req.url(charges_url)
73
- req.headers['Content-Type'] = 'application/json'
74
- req.headers['Authorization'] = "Basic #{basic}"
75
- req.body = parms
76
- end.env
77
- @data = @resp[:body]
78
- end
79
-
80
- def void
81
- api_call(void_url)
82
- end
83
-
84
- # :nodoc:
85
- # def ca_path
86
- # return VTDirect.config["ca_path"] ? VTDirect.config["ca_path"] : Config::CA_PATH
87
- # end
88
-
89
- # :nodoc:
90
- def server_host
91
- return VTDirect.config["server_host"] ? VTDirect.config["server_host"] : Config::SERVER_HOST
92
- end
93
-
94
- # :nodoc:
95
- def tokens_url
96
- return Client.config["tokens_url"] ? Client.config["tokens_url"] : Config::TOKENS_URL
97
- end
98
-
99
- # :nodoc:
100
- def charges_url
101
- return Client.config["charges_url"] ? Client.config["charges_url"] : Config::CHARGES_URL
102
- end
103
-
104
- # :nodoc:
105
- def void_url
106
- return Client.config["void_url"] ? Client.config["void_url"] : Config::VOID_URL
107
- end
108
-
109
- # :nodoc:
110
- def server_key
111
- return VTDirect.config["server_key"]
112
- end
113
-
114
- # :nodoc:
115
- def server_key= new_server_key
116
- VTDirect.config["server_key"] = new_server_key
117
- end
118
-
119
- private
120
-
121
- def api_call(url)
122
- parms = prepare_params(@@attr).to_json
123
- basic = Base64.encode64("#{server_key}:")
124
- copt = {:url => server_host}
125
- copt[:ssl] = { :ca_path => VTDirect.config["ca_path"] } if VTDirect.config["ca_path"] #"/usr/lib/ssl/certs"
126
- conn = Faraday.new( copt )
127
- @resp = conn.post do |req|
128
- req.url(url)
129
- req.headers['Content-Type'] = 'application/json'
130
- req.headers['Authorization'] = "Basic #{basic}"
131
- req.body = parms
132
- end.env
133
- @data = @resp[:body]
134
- end
135
-
136
- def prepare_params(*arg)
137
- params = {}
138
- arg.flatten.each do |key|
139
- value = self.send(key)
140
- params[key.to_s.downcase] = value if value
141
- end
142
- return params
143
- end
144
- end
145
- end