wompi 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 87a08985ec5e538ee8e047d41e26fb3e476b9bc917ead1fac57c26d10b040db7
4
+ data.tar.gz: eedcb04131861fa16879bf912dae734bce1166f8e5b1856b8db3a86a39070d65
5
+ SHA512:
6
+ metadata.gz: 4748182ebbebf95f36622ba54125bd9f421430977e6fdd4666749b903d44df051727daa2fe02d6816d6d8d34601b456db839c4bde3a0c2c471dd52158d12185d
7
+ data.tar.gz: d207f609468edb242a6275c80640df8a24de89f7c04d1766b0919dcb8c61f9940db156faf19655ffbe35b680c1265b36d945c9ddaf3bf91403a7145ecb2e04d8
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ *.gem
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at simoncorreaocampo@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in frm_mercury.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Simon C
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # Wompi client
2
+
3
+ Ruby gem to use the Wompi API simple (Is still in progress)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'wompi'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```sh
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```sh
22
+ $ gem install wompi
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ For Rails First create an wompi.rb in your config/initializers
28
+
29
+ ```ruby
30
+ require "wompi"
31
+
32
+ Wompi::RApi.configure do |config|
33
+ config.pub_key = "pub_key"
34
+ config.prv_key = "prv_key"
35
+ config.webhook = "https://domain.com/wompi_webhook"
36
+ config.sandbox = true # or false for production
37
+ end
38
+
39
+ ```
40
+
41
+ ## Flow
42
+
43
+ ### First login
44
+
45
+ ```ruby
46
+ wompi_login = Wompi::RApi::Login.new
47
+ wompi_login.get_acceptance_token
48
+
49
+ wompi_card = Wompi::RApi::PaymentMethod.new(wompi_login)
50
+ wompi_card.as_dummy_card(params["card_status"])
51
+ wompi_card.create
52
+
53
+ if wompi_card.success?
54
+ # DO something
55
+ end
56
+
57
+ ```
58
+
59
+ ### Second prepare and create transaction
60
+
61
+ ```ruby
62
+ # login
63
+ wompi_login = Wompi::RApi::Login.new
64
+ wompi_login.get_acceptance_token
65
+
66
+ # handle payment method
67
+ wompi_card = Wompi::RApi::PaymentMethod.new(wompi_login)
68
+ wompi_card.as_card_with_known_id("token")
69
+ wompi_card.as_dummy_card("APPROVED") # or "DECLINED"
70
+ wompi_card.as_card("number", "cvc", "exp_month", "exp_year", "holder")
71
+ wompi_card.as_dummy_nequi("APPROVED") # or "DECLINED"
72
+ wompi_card.as_nequi("phone")
73
+ wompi_card.get_nequi("id")
74
+ wompi_card.check_nequi("phone") # use after initializing PaymentMethod and using get_nequi
75
+
76
+ # create payment source from payment method
77
+ wompi_source = Wompi::RApi::PaymentSource.new(wompi_login)
78
+ wompi_source.create(wompi_card, "email")
79
+
80
+ # create transaction
81
+ wompi_trans = Wompi::RApi::Transaction.new(wompi_login)
82
+ wompi_trans.prepare("amount_in_cents", "currency", "customer_email", "payment_source", "installments", "reference")
83
+ wompi_trans.create
84
+
85
+ if wompi_trans.success?
86
+ # DO something
87
+ end
88
+
89
+ ```
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "wompi"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/wompi.rb ADDED
@@ -0,0 +1,10 @@
1
+ require "wompi/r_api"
2
+ require "wompi/r_api/request"
3
+ require "wompi/r_api/login"
4
+ require "wompi/r_api/payment_method"
5
+ require "wompi/r_api/payment_source"
6
+ require "wompi/r_api/transaction"
7
+
8
+ module Wompi
9
+
10
+ end
@@ -0,0 +1,20 @@
1
+ module Wompi
2
+ module RApi
3
+ class << self
4
+ require "base64"
5
+ attr_accessor :pub_key, :prv_key, :sandbox, :webhook
6
+
7
+ def configure(&block)
8
+ block.call(self)
9
+ end
10
+
11
+ def get_base_url
12
+ if @sandbox == true
13
+ "https://sandbox.wompi.co/"
14
+ else
15
+ "https://production.wompi.co/"
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,23 @@
1
+ module Wompi
2
+ module RApi
3
+ class Login < Request
4
+ attr_accessor :acceptance_token, :permalink
5
+
6
+ def initialize
7
+ super
8
+ end
9
+
10
+ def get_acceptance_token
11
+ @http_verb = 'Get'
12
+ @url += "v1/merchants/#{RApi.pub_key}"
13
+
14
+ http
15
+ if success?
16
+ @acceptance_token = @response["data"]["presigned_acceptance"]["acceptance_token"]
17
+ @permalink = @response["data"]["presigned_acceptance"]["permalink"]
18
+ self
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,122 @@
1
+ module Wompi
2
+ module RApi
3
+ class PaymentMethod < Request
4
+
5
+ attr_accessor :type, :id, :created_at, :brand, :name, :last_four, :bin, :exp_year, :exp_month, :holder, :expires_at, :phone_number, :status
6
+
7
+ def initialize(login)
8
+ super(login, "pub_key")
9
+ end
10
+
11
+ def set_data
12
+ @id = @response["data"]["id"]
13
+ @created_at = @response["data"]["created_at"]
14
+ @brand = @response["data"]["brand"]
15
+ @name = @response["data"]["name"]
16
+ @last_four = @response["data"]["last_four"]
17
+ @bin = @response["data"]["bin"]
18
+ @exp_year = @response["data"]["exp_year"]
19
+ @exp_month = @response["data"]["exp_month"]
20
+ @holder = @response["data"]["card_holder"]
21
+ @expires_at = @response["data"]["expires_at"]
22
+ @phone_number = @response["data"]["phone_number"]
23
+ @status = @response["data"]["status"]
24
+ end
25
+
26
+ def as_dummy_card(status)
27
+ @type = "CARD"
28
+ @params = {
29
+ number: status == "APPROVED" ? "4242424242424242" : "4111111111111111",
30
+ cvc: "123",
31
+ exp_month: "01",
32
+ exp_year: "#{(Date.today + 1.year).year.to_s.last(2)}",
33
+ card_holder: "Han Solo Berger"
34
+ }
35
+ end
36
+
37
+
38
+ def as_card(number, cvc, exp_month, exp_year, holder)
39
+ @type = "CARD"
40
+ @params = {
41
+ number: "#{number}",
42
+ cvc: "#{cvc}",
43
+ exp_month: "#{exp_month}",
44
+ exp_year: "#{exp_year}",
45
+ card_holder: "#{holder}"
46
+ }
47
+ end
48
+
49
+ def as_card_with_known_id(id)
50
+ @type = "CARD"
51
+ @id = id
52
+ end
53
+
54
+ def as_dummy_nequi(status)
55
+ @type = "NEQUI"
56
+ @params = {
57
+ phone_number: status == "APPROVED" ? "3991111111" : "3992222222"
58
+ }
59
+ end
60
+
61
+ def as_nequi(phone)
62
+ @type = "NEQUI"
63
+ @params = {
64
+ phone_number: "#{phone}"
65
+ }
66
+ end
67
+
68
+ def check_nequi
69
+ @http_verb = 'Get'
70
+ @url = "v1/tokens/nequi/#{@id}"
71
+
72
+ if @response["data"]
73
+ @status = @response["data"]["status"]
74
+ end
75
+ self
76
+ end
77
+
78
+ def get_nequi(id=nil)
79
+ @id = id unless id.nil?
80
+ @http_verb = 'Get'
81
+ @url += "v1/tokens/nequi/#{@id}"
82
+
83
+ http
84
+
85
+ if success?
86
+ set_data
87
+ self
88
+ end
89
+ end
90
+
91
+ def create
92
+ @http_verb = 'Post'
93
+ if @type == "CARD"
94
+ @url += "v1/tokens/cards"
95
+ else
96
+ @url += "v1/tokens/nequi"
97
+ end
98
+
99
+ http
100
+
101
+ if success?
102
+ if @type == "CARD"
103
+ if @response["status"] == "CREATED"
104
+ set_data
105
+ self
106
+ else
107
+ nil
108
+ end
109
+ else
110
+ if ["APPROVED", "PENDING"].include? @response["status"]
111
+ set_data
112
+ self
113
+ else
114
+ nil
115
+ end
116
+ end
117
+ end
118
+ end
119
+
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,36 @@
1
+ module Wompi
2
+ module RApi
3
+ class PaymentSource < Request
4
+
5
+ attr_accessor :id, :customer_email, :status
6
+
7
+ def initialize(login)
8
+ super(login, "prv_key")
9
+ end
10
+
11
+ def create(payment_method, customer_email)
12
+ @http_verb = 'Post'
13
+ @url += "v1/payment_sources"
14
+ @params = {
15
+ type: payment_method.type,
16
+ token: payment_method.id,
17
+ customer_email: customer_email,
18
+ acceptance_token: @login.acceptance_token
19
+ }
20
+
21
+ http
22
+
23
+ if success?
24
+ if @response["data"]
25
+ @id = @response["data"]["id"]
26
+ @status = @response["data"]["status"]
27
+ self
28
+ else
29
+ nil
30
+ end
31
+ end
32
+ end
33
+
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,78 @@
1
+ module Wompi
2
+ module RApi
3
+ class Request
4
+
5
+ require 'uri'
6
+ require 'net/https'
7
+ require 'json'
8
+
9
+ attr_accessor :url, :_url, :params, :headers, :login, :with_authentication_key
10
+
11
+ attr_reader :response, :http_verb, :error
12
+
13
+ def initialize(login=nil, with_authentication_key=false)
14
+ @login = login
15
+ @with_authentication_key = with_authentication_key
16
+ @url = RApi.get_base_url
17
+ end
18
+
19
+ def success?
20
+ @error.nil? && !@response.nil?
21
+ end
22
+
23
+ def fail?
24
+ !@error.nil?
25
+ end
26
+
27
+ private
28
+
29
+ def url
30
+ @url ||= _url
31
+ end
32
+
33
+ def reset_url
34
+ @url = url
35
+ end
36
+
37
+ def http
38
+
39
+ uri = URI.parse(@url)
40
+
41
+ https = Net::HTTP.new(uri.host,uri.port)
42
+
43
+ https.use_ssl = true
44
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
45
+
46
+ net_class = Object.const_get("Net::HTTP::#{http_verb}")
47
+ @headers = {"Content-Type" => "application/json"}
48
+
49
+ if @with_authentication_key == "pub_key"
50
+ @headers["Authorization"] = "Bearer #{RApi.pub_key}"
51
+ end
52
+ if @with_authentication_key == "prv_key"
53
+ @headers["Authorization"] = "Bearer #{RApi.prv_key}"
54
+ end
55
+ request = net_class.new(uri, initheader = @headers)
56
+
57
+ if http_verb == "Post"
58
+
59
+ request.body = @params.to_json
60
+ end
61
+
62
+ request = https.request(request)
63
+
64
+ if request.is_a?(Net::HTTPSuccess)
65
+ begin
66
+ @response = JSON.parse(request.body)
67
+ rescue
68
+ @response = request.body
69
+ end
70
+ @error = nil
71
+ else
72
+ @response = nil
73
+ @error = JSON.parse(request.body)
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,87 @@
1
+
2
+ module Wompi
3
+ module RApi
4
+ class Transaction < Request
5
+
6
+ attr_accessor :id, :amount_in_cents, :currency, :customer_email, :payment_method, :reference, :payment_source, :status
7
+
8
+ def initialize(login)
9
+ super(login, "prv_key")
10
+ end
11
+
12
+ def set_data
13
+ @id = @response["data"]["id"]
14
+ @status = @response["data"]["status"]
15
+ end
16
+
17
+ def prepare(amount_in_cents, currency, customer_email, payment_source, installments, reference)
18
+ @params = {
19
+ amount_in_cents: amount_in_cents,
20
+ currency: currency,
21
+ customer_email: customer_email,
22
+ payment_method: {
23
+ installments: installments
24
+ },
25
+ reference: "#{reference}",
26
+ payment_source_id: payment_source.id,
27
+ acceptance_token: @login.acceptance_token
28
+ }
29
+ end
30
+
31
+ def get(id=nil)
32
+ @id = id unless id.nil?
33
+ @http_verb = 'Get'
34
+ @url += "v1/transactions/#{@id}"
35
+
36
+ http
37
+
38
+ if success?
39
+ set_data
40
+ self
41
+ end
42
+ end
43
+
44
+ def search(reference)
45
+ @http_verb = 'Get'
46
+ @url += "v1/transactions?reference=#{reference}"
47
+
48
+ http
49
+
50
+ if success?
51
+ @response["data"]
52
+ else
53
+ []
54
+ end
55
+ end
56
+
57
+ def void(id=nil)
58
+ @id = id unless id.nil?
59
+ @http_verb = 'Post'
60
+ @url += "v1/transactions/#{@id}/void"
61
+
62
+ http
63
+
64
+ if success?
65
+ set_data
66
+ self
67
+ end
68
+ end
69
+
70
+ def create
71
+ @http_verb = 'Post'
72
+ @url += "v1/transactions"
73
+ @params[:extra] = {
74
+ async_payment_url: Rapi.webhook
75
+ }
76
+
77
+ http
78
+
79
+ if success?
80
+ @id = @response["data"]["id"]
81
+ self
82
+ end
83
+ end
84
+
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,3 @@
1
+ module Wompi
2
+ VERSION = "0.0.1"
3
+ end
data/wompi.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "wompi/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "wompi"
7
+ spec.version = Wompi::VERSION
8
+ spec.authors = ["MakarovCode"]
9
+ spec.email = ["simoncorreaocampo@gmail.com"]
10
+
11
+ spec.summary = "Gem to use the Wompi API simple"
12
+ spec.description = "Ruby gem to use the Wompi API simple"
13
+ spec.homepage = "https://github.com/MakarovCode/WompiApi"
14
+ spec.license = "MIT"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_development_dependency "bundler", "~> 2.0"
26
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wompi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - MakarovCode
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-06-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ description: Ruby gem to use the Wompi API simple
28
+ email:
29
+ - simoncorreaocampo@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - CODE_OF_CONDUCT.md
36
+ - Gemfile
37
+ - LICENSE.txt
38
+ - README.md
39
+ - bin/console
40
+ - bin/setup
41
+ - lib/wompi.rb
42
+ - lib/wompi/r_api.rb
43
+ - lib/wompi/r_api/login.rb
44
+ - lib/wompi/r_api/payment_method.rb
45
+ - lib/wompi/r_api/payment_source.rb
46
+ - lib/wompi/r_api/request.rb
47
+ - lib/wompi/r_api/transaction.rb
48
+ - lib/wompi/version.rb
49
+ - wompi.gemspec
50
+ homepage: https://github.com/MakarovCode/WompiApi
51
+ licenses:
52
+ - MIT
53
+ metadata: {}
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubygems_version: 3.1.2
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: Gem to use the Wompi API simple
73
+ test_files: []