paymongo 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circleci/config.yml +47 -0
- data/.github/workflows/gempush.yml +41 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +9 -0
- data/CHANGELOG.md +10 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +78 -0
- data/LICENSE.txt +21 -0
- data/README.md +85 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/paymongo.rb +24 -0
- data/lib/paymongo/base_module.rb +13 -0
- data/lib/paymongo/configuration.rb +104 -0
- data/lib/paymongo/error_result.rb +14 -0
- data/lib/paymongo/exceptions.rb +6 -0
- data/lib/paymongo/gateway.rb +44 -0
- data/lib/paymongo/http.rb +20 -0
- data/lib/paymongo/successful_result.rb +20 -0
- data/lib/paymongo/transaction.rb +34 -0
- data/lib/paymongo/transaction_gateway.rb +47 -0
- data/lib/paymongo/version.rb +3 -0
- data/paymongo.gemspec +43 -0
- metadata +198 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: '069be6421cde51c219db3450deabbe33b68d3e07123ebbe5f6166a5a334bb743'
|
4
|
+
data.tar.gz: 97581f60831b4c6871f889096961185535d8faefc4e2b827c79c99fa59e5ddcd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 59fe204179a8b5fd5a9a7449dfbaf412b96e8782b4e40f0fc6ee4331795c29a3a24eb4af232af2979f106c5d5209cf9c687ac444b78b91683ff12f3677b4eb5e
|
7
|
+
data.tar.gz: b53123206b825bde39e9874a2277a46bb222fe590fd645acb1e0152d024f83cc7119b99398fc41143aed998c0200f8a0bb57b9a6713180e71931cfd6ecb4ed87
|
@@ -0,0 +1,47 @@
|
|
1
|
+
version: 2
|
2
|
+
jobs:
|
3
|
+
build:
|
4
|
+
docker:
|
5
|
+
- image: circleci/ruby:2.6.5
|
6
|
+
working_directory: ~/repo
|
7
|
+
steps:
|
8
|
+
- checkout
|
9
|
+
|
10
|
+
# Download and cache dependencies
|
11
|
+
- restore_cache:
|
12
|
+
keys:
|
13
|
+
- v1-dependencies-{{ checksum "Gemfile.lock" }}
|
14
|
+
# fallback to using the latest cache if no exact match is found
|
15
|
+
- v1-dependencies-
|
16
|
+
|
17
|
+
- run:
|
18
|
+
name: install dependencies
|
19
|
+
command: |
|
20
|
+
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
21
|
+
|
22
|
+
- save_cache:
|
23
|
+
paths:
|
24
|
+
- ./vendor/bundle
|
25
|
+
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
|
26
|
+
|
27
|
+
# run tests!
|
28
|
+
- run:
|
29
|
+
name: run tests
|
30
|
+
command: |
|
31
|
+
mkdir /tmp/test-results
|
32
|
+
TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | \
|
33
|
+
circleci tests split --split-by=timings)"
|
34
|
+
|
35
|
+
bundle exec rspec \
|
36
|
+
--format progress \
|
37
|
+
--format RspecJunitFormatter \
|
38
|
+
--out /tmp/test-results/rspec.xml \
|
39
|
+
--format progress \
|
40
|
+
$TEST_FILES
|
41
|
+
|
42
|
+
# collect reports
|
43
|
+
- store_test_results:
|
44
|
+
path: /tmp/test-results
|
45
|
+
- store_artifacts:
|
46
|
+
path: /tmp/test-results
|
47
|
+
destination: test-results
|
@@ -0,0 +1,41 @@
|
|
1
|
+
name: Ruby Gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
build:
|
10
|
+
name: Build + Publish
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
|
13
|
+
steps:
|
14
|
+
- uses: actions/checkout@master
|
15
|
+
- name: Set up Ruby 2.6
|
16
|
+
uses: actions/setup-ruby@v1
|
17
|
+
with:
|
18
|
+
ruby-version: 2.6.x
|
19
|
+
|
20
|
+
- name: Publish to GPR
|
21
|
+
run: |
|
22
|
+
mkdir -p $HOME/.gem
|
23
|
+
touch $HOME/.gem/credentials
|
24
|
+
chmod 0600 $HOME/.gem/credentials
|
25
|
+
printf -- "---\n:github: Bearer ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
26
|
+
gem build *.gemspec
|
27
|
+
gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
|
28
|
+
env:
|
29
|
+
GEM_HOST_API_KEY: ${{secrets.GITHUB_TOKEN}}
|
30
|
+
OWNER: makisu
|
31
|
+
|
32
|
+
- name: Publish to RubyGems
|
33
|
+
run: |
|
34
|
+
mkdir -p $HOME/.gem
|
35
|
+
touch $HOME/.gem/credentials
|
36
|
+
chmod 0600 $HOME/.gem/credentials
|
37
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
38
|
+
gem build *.gemspec
|
39
|
+
gem push *.gem
|
40
|
+
env:
|
41
|
+
GEM_HOST_API_KEY: ${{secrets.RUBYGEMS_AUTH_TOKEN}}
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
|
+
and this project adheres to [Semantic
|
6
|
+
Versioning](https://semver.org/spec/v2.0.0.html).
|
7
|
+
|
8
|
+
## [1.0.0]
|
9
|
+
### Added
|
10
|
+
- Initial release
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -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 xlablaza@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
data/Gemfile.lock
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
paymongo (1.0.0)
|
5
|
+
activesupport
|
6
|
+
gem_config
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activesupport (6.0.1)
|
12
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
+
i18n (>= 0.7, < 2)
|
14
|
+
minitest (~> 5.1)
|
15
|
+
tzinfo (~> 1.1)
|
16
|
+
zeitwerk (~> 2.2)
|
17
|
+
addressable (2.6.0)
|
18
|
+
public_suffix (>= 2.0.2, < 4.0)
|
19
|
+
byebug (11.0.1)
|
20
|
+
coderay (1.1.2)
|
21
|
+
concurrent-ruby (1.1.5)
|
22
|
+
crack (0.4.3)
|
23
|
+
safe_yaml (~> 1.0.0)
|
24
|
+
diff-lcs (1.3)
|
25
|
+
gem_config (0.3.1)
|
26
|
+
hashdiff (1.0.0)
|
27
|
+
i18n (1.7.0)
|
28
|
+
concurrent-ruby (~> 1.0)
|
29
|
+
method_source (0.9.2)
|
30
|
+
minitest (5.13.0)
|
31
|
+
prettier (0.15.0)
|
32
|
+
pry (0.12.2)
|
33
|
+
coderay (~> 1.1.0)
|
34
|
+
method_source (~> 0.9.0)
|
35
|
+
pry-byebug (3.7.0)
|
36
|
+
byebug (~> 11.0)
|
37
|
+
pry (~> 0.10)
|
38
|
+
public_suffix (3.1.1)
|
39
|
+
rake (10.5.0)
|
40
|
+
rspec (3.8.0)
|
41
|
+
rspec-core (~> 3.8.0)
|
42
|
+
rspec-expectations (~> 3.8.0)
|
43
|
+
rspec-mocks (~> 3.8.0)
|
44
|
+
rspec-core (3.8.2)
|
45
|
+
rspec-support (~> 3.8.0)
|
46
|
+
rspec-expectations (3.8.4)
|
47
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
48
|
+
rspec-support (~> 3.8.0)
|
49
|
+
rspec-mocks (3.8.1)
|
50
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
51
|
+
rspec-support (~> 3.8.0)
|
52
|
+
rspec-support (3.8.2)
|
53
|
+
safe_yaml (1.0.5)
|
54
|
+
thread_safe (0.3.6)
|
55
|
+
tzinfo (1.2.5)
|
56
|
+
thread_safe (~> 0.1)
|
57
|
+
vcr (5.0.0)
|
58
|
+
webmock (3.6.2)
|
59
|
+
addressable (>= 2.3.6)
|
60
|
+
crack (>= 0.3.2)
|
61
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
62
|
+
zeitwerk (2.2.1)
|
63
|
+
|
64
|
+
PLATFORMS
|
65
|
+
ruby
|
66
|
+
|
67
|
+
DEPENDENCIES
|
68
|
+
bundler (~> 2.0)
|
69
|
+
paymongo!
|
70
|
+
prettier
|
71
|
+
pry-byebug
|
72
|
+
rake (~> 10.0)
|
73
|
+
rspec (~> 3.0)
|
74
|
+
vcr
|
75
|
+
webmock
|
76
|
+
|
77
|
+
BUNDLED WITH
|
78
|
+
2.0.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Xavier Luis Ablaza
|
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,85 @@
|
|
1
|
+
# PayMongo Ruby Library
|
2
|
+
[![Build
|
3
|
+
Status](https://travis-ci.org/makisu/paymongo_ruby.svg?branch=master)](https://travis-ci.com/makisu/paymongo_ruby)
|
4
|
+
|
5
|
+
Charge credit cards using [PayMongo](https://developers.paymongo.com/) in Ruby.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'paymongo'
|
13
|
+
```
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem install paymongo
|
19
|
+
```
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
In an initializer, you can set default values:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
Paymongo.configure do |c|
|
27
|
+
c.secret_key = "PAYMONGO-SK-API-KEY"
|
28
|
+
c.public_key = "PAYMONGO-PK-API-KEY"
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
## Initializing a Gateway
|
33
|
+
|
34
|
+
This is the instance that you will be interacting with to create payments.
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
# This gateway grabs defaults from config
|
38
|
+
gateway = Paymongo::Gateway.new(Paymongo::Configuration.new)
|
39
|
+
|
40
|
+
# Only to override the defaults that were set in the config
|
41
|
+
gateway = Paymongo::Gateway.new(
|
42
|
+
secret_key: "...",
|
43
|
+
public_key: "..."
|
44
|
+
)
|
45
|
+
```
|
46
|
+
|
47
|
+
## Charge a Card
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
result = gateway.transaction.sale(
|
51
|
+
token: token_from_the_client,
|
52
|
+
amount: 10000,
|
53
|
+
currency: "PHP",
|
54
|
+
# Below are optional
|
55
|
+
description: "Payment for Invoice #0001",
|
56
|
+
statement_descriptor: "MAKISU.CO"
|
57
|
+
)
|
58
|
+
```
|
59
|
+
|
60
|
+
## Running the test suite
|
61
|
+
|
62
|
+
1. Install the latest Ruby
|
63
|
+
|
64
|
+
2. Copy `config.yml.sample` to `config.yml` then run:
|
65
|
+
```
|
66
|
+
bundle install
|
67
|
+
bundle exec rspec spec
|
68
|
+
```
|
69
|
+
|
70
|
+
3. You can replace values in `config.yml` with values from your PayMongo
|
71
|
+
dashboard
|
72
|
+
|
73
|
+
## Development
|
74
|
+
|
75
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
76
|
+
|
77
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
78
|
+
|
79
|
+
## Contributing
|
80
|
+
|
81
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/makisu/paymongo_ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
82
|
+
|
83
|
+
## License
|
84
|
+
|
85
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "paymongo"
|
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
data/lib/paymongo.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'gem_config'
|
2
|
+
require 'paymongo/version'
|
3
|
+
require 'net/http'
|
4
|
+
require 'net/https'
|
5
|
+
require 'json'
|
6
|
+
require 'paymongo/base_module'
|
7
|
+
require 'paymongo/gateway'
|
8
|
+
require 'paymongo/configuration'
|
9
|
+
require 'paymongo/exceptions'
|
10
|
+
require 'paymongo/transaction_gateway'
|
11
|
+
require 'paymongo/transaction'
|
12
|
+
require 'paymongo/http'
|
13
|
+
require 'paymongo/successful_result'
|
14
|
+
require 'paymongo/error_result'
|
15
|
+
|
16
|
+
module Paymongo
|
17
|
+
include GemConfig::Base
|
18
|
+
|
19
|
+
with_configuration do
|
20
|
+
has :secret_key, classes: String
|
21
|
+
has :public_key, classes: String
|
22
|
+
has :logger
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Paymongo
|
2
|
+
module BaseModule
|
3
|
+
module Methods
|
4
|
+
def set_instance_variables_from_hash(hash)
|
5
|
+
hash.each { |key, value| instance_variable_set "@#{key}", value }
|
6
|
+
end
|
7
|
+
end
|
8
|
+
def self.included(klass)
|
9
|
+
klass.extend Methods
|
10
|
+
end
|
11
|
+
include Methods
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
module Paymongo
|
2
|
+
class Configuration
|
3
|
+
API_VERSION = '1'
|
4
|
+
|
5
|
+
READABLE_ATTRIBUTES = %i[public_key secret_key]
|
6
|
+
|
7
|
+
WRITABLE_ATTRIBUTES = %i[logger public_key secret_key]
|
8
|
+
|
9
|
+
class << self
|
10
|
+
attr_writer *WRITABLE_ATTRIBUTES
|
11
|
+
end
|
12
|
+
attr_reader *READABLE_ATTRIBUTES
|
13
|
+
attr_writer *WRITABLE_ATTRIBUTES
|
14
|
+
|
15
|
+
def self.expectant_reader(*attributes)
|
16
|
+
attributes.each do |attribute|
|
17
|
+
(
|
18
|
+
class << self
|
19
|
+
self
|
20
|
+
end
|
21
|
+
)
|
22
|
+
.send(:define_method, attribute) do
|
23
|
+
attribute_value = instance_variable_get("@#{attribute}")
|
24
|
+
if attribute_value.nil? || attribute_value.to_s.empty?
|
25
|
+
raise ConfigurationError.new(
|
26
|
+
"Paymongo::Configuration.#{attribute.to_s} needs to be set"
|
27
|
+
)
|
28
|
+
end
|
29
|
+
attribute_value
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
expectant_reader *READABLE_ATTRIBUTES
|
34
|
+
|
35
|
+
def self.gateway
|
36
|
+
Paymongo::Gateway.new(instantiate)
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.instantiate
|
40
|
+
config = new
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.logger
|
44
|
+
@logger ||= _default_logger
|
45
|
+
end
|
46
|
+
|
47
|
+
def initialize(options = {})
|
48
|
+
WRITABLE_ATTRIBUTES.each do |attr|
|
49
|
+
instance_variable_set "@#{attr}",
|
50
|
+
options[attr] || Paymongo.configuration.send(attr)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def api_version
|
55
|
+
API_VERSION
|
56
|
+
end
|
57
|
+
|
58
|
+
def base_url
|
59
|
+
"#{protocol}://#{server}:#{port}/v#{API_VERSION}"
|
60
|
+
end
|
61
|
+
|
62
|
+
def https
|
63
|
+
Http.new(self)
|
64
|
+
end
|
65
|
+
|
66
|
+
def logger
|
67
|
+
@logger ||= self.class._default_logger
|
68
|
+
end
|
69
|
+
|
70
|
+
def port
|
71
|
+
443
|
72
|
+
end
|
73
|
+
|
74
|
+
def protocol
|
75
|
+
'https'
|
76
|
+
end
|
77
|
+
|
78
|
+
def server
|
79
|
+
'api.paymongo.com'
|
80
|
+
end
|
81
|
+
|
82
|
+
def ssl?
|
83
|
+
true
|
84
|
+
end
|
85
|
+
|
86
|
+
def self._default_logger
|
87
|
+
logger = Logger.new(STDOUT)
|
88
|
+
logger.level = Logger::INFO
|
89
|
+
logger
|
90
|
+
end
|
91
|
+
|
92
|
+
def inspect
|
93
|
+
super.gsub(/@secret_key=\".*\"/, '@secret_key="[FILTERED]"')
|
94
|
+
end
|
95
|
+
|
96
|
+
def assert_has_keys
|
97
|
+
if public_key.nil? || secret_key.nil?
|
98
|
+
raise ConfigurationError.new(
|
99
|
+
'Paymongo::Gateway public_key and secret_key are required.'
|
100
|
+
)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Paymongo
|
2
|
+
class Gateway
|
3
|
+
attr_reader :config
|
4
|
+
|
5
|
+
def initialize(config)
|
6
|
+
if config.is_a?(Hash)
|
7
|
+
@config = Configuration.new config
|
8
|
+
elsif config.is_a?(Paymongo::Configuration)
|
9
|
+
@config = config
|
10
|
+
else
|
11
|
+
raise ArgumentError, 'config is an invalid type'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def charge_card(
|
16
|
+
token:, amount:, currency:, description: '', statement_descriptor: ''
|
17
|
+
)
|
18
|
+
header = { 'Content-Type': 'application/json' }
|
19
|
+
payment_params = {
|
20
|
+
data: {
|
21
|
+
attributes: {
|
22
|
+
amount: amount,
|
23
|
+
currency: currency,
|
24
|
+
description: description,
|
25
|
+
statement_descriptor: statement_descriptor,
|
26
|
+
source: { id: token, type: 'token' }
|
27
|
+
}
|
28
|
+
}
|
29
|
+
}.to_json
|
30
|
+
|
31
|
+
uri = URI.parse('https://api.paymongo.com/v1/payments')
|
32
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
33
|
+
https.use_ssl = true
|
34
|
+
req = Net::HTTP::Post.new(uri.path, header)
|
35
|
+
req.basic_auth(config.secret_key, '')
|
36
|
+
req.body = payment_params
|
37
|
+
https.request(req)
|
38
|
+
end
|
39
|
+
|
40
|
+
def transaction
|
41
|
+
TransactionGateway.new(self)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Paymongo
|
2
|
+
class Http
|
3
|
+
def initialize(config)
|
4
|
+
@config = config
|
5
|
+
end
|
6
|
+
|
7
|
+
def post(path, params = nil)
|
8
|
+
header = { 'Content-Type': 'application/json' }
|
9
|
+
uri = URI.parse(path)
|
10
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
11
|
+
https.use_ssl = true
|
12
|
+
req = Net::HTTP::Post.new(uri.path, header)
|
13
|
+
# TODO: Put password in basic_auth as part of config
|
14
|
+
req.basic_auth(@config.secret_key, '')
|
15
|
+
req.body = params[:transaction].to_json
|
16
|
+
res = https.request(req)
|
17
|
+
JSON.parse(res.body).with_indifferent_access
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Paymongo
|
2
|
+
class SuccessfulResult
|
3
|
+
attr_reader :transaction
|
4
|
+
|
5
|
+
def initialize(attributes = {})
|
6
|
+
@attrs = attributes.keys
|
7
|
+
attributes.each { |key, value| instance_variable_set("@#{key}", value) }
|
8
|
+
end
|
9
|
+
|
10
|
+
def inspect
|
11
|
+
inspected_attributes =
|
12
|
+
@attrs.map { |attr| "#{attr}:#{send(attr).inspect}" }
|
13
|
+
"#<#{self.class} #{inspected_attributes.join(' ')}>"
|
14
|
+
end
|
15
|
+
|
16
|
+
def success?
|
17
|
+
true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Paymongo
|
2
|
+
class Transaction
|
3
|
+
include BaseModule
|
4
|
+
|
5
|
+
attr_reader :id
|
6
|
+
attr_reader :type
|
7
|
+
attr_reader :amount
|
8
|
+
attr_reader :billing
|
9
|
+
attr_reader :created
|
10
|
+
attr_reader :currency
|
11
|
+
attr_reader :description
|
12
|
+
attr_reader :external_reference_number
|
13
|
+
attr_reader :fee
|
14
|
+
attr_reader :livemode
|
15
|
+
attr_reader :net_amount
|
16
|
+
attr_reader :statement_descriptor
|
17
|
+
attr_reader :status
|
18
|
+
attr_reader :updated
|
19
|
+
|
20
|
+
def initialize(gateway, attributes)
|
21
|
+
@gateway = gateway
|
22
|
+
set_instance_variables_from_hash(attributes[:attributes])
|
23
|
+
@id = attributes[:id]
|
24
|
+
@type = attributes[:type]
|
25
|
+
# TODO: Add relationships hash
|
26
|
+
end
|
27
|
+
class << self
|
28
|
+
protected :new
|
29
|
+
def _new(*args)
|
30
|
+
self.new(*args)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Paymongo
|
2
|
+
class TransactionGateway
|
3
|
+
def initialize(gateway)
|
4
|
+
@gateway = gateway
|
5
|
+
@config = gateway.config
|
6
|
+
@config.assert_has_keys
|
7
|
+
end
|
8
|
+
|
9
|
+
def sale(attributes)
|
10
|
+
# Wrap the hash
|
11
|
+
create(
|
12
|
+
{
|
13
|
+
data: {
|
14
|
+
attributes: {
|
15
|
+
amount: attributes[:amount],
|
16
|
+
currency: attributes[:currency],
|
17
|
+
description: attributes[:description],
|
18
|
+
statement_descriptor: attributes[:statement_descriptor],
|
19
|
+
source: { id: attributes[:token], type: 'token' }
|
20
|
+
}
|
21
|
+
}
|
22
|
+
}
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
def create(attributes)
|
27
|
+
_do_create '/payments', transaction: attributes
|
28
|
+
end
|
29
|
+
|
30
|
+
def _do_create(path, params = nil)
|
31
|
+
response = @config.https.post("#{@config.base_url}#{path}", params)
|
32
|
+
_handle_transaction_response(response)
|
33
|
+
end
|
34
|
+
|
35
|
+
def _handle_transaction_response(response)
|
36
|
+
if response[:data]
|
37
|
+
SuccessfulResult.new(
|
38
|
+
transaction: Transaction._new(@gateway, response[:data])
|
39
|
+
)
|
40
|
+
elsif response[:errors]
|
41
|
+
ErrorResult.new(@gateway, response[:errors])
|
42
|
+
else
|
43
|
+
raise UnexpectedError, 'expected :data'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/paymongo.gemspec
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "paymongo/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "paymongo"
|
7
|
+
spec.version = Paymongo::VERSION
|
8
|
+
spec.authors = ["Xavi Ablaza"]
|
9
|
+
spec.email = ["dev@makisu.co"]
|
10
|
+
|
11
|
+
spec.summary = %q{Charge credit cards using PayMongo in Ruby.}
|
12
|
+
spec.homepage = "https://github.com/makisu/paymongo"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
if spec.respond_to?(:metadata)
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
spec.metadata["source_code_uri"] = "https://github.com/makisu/paymongoy"
|
18
|
+
spec.metadata["changelog_uri"] = "https://github.com/makisu/paymongo/blob/master/CHANGELOG.md"
|
19
|
+
else
|
20
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
21
|
+
"public gem pushes."
|
22
|
+
end
|
23
|
+
|
24
|
+
# Specify which files should be added to the gem when it is released.
|
25
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
26
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
27
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_dependency "activesupport"
|
34
|
+
spec.add_dependency "gem_config"
|
35
|
+
|
36
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
37
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
38
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
39
|
+
spec.add_development_dependency "pry-byebug"
|
40
|
+
spec.add_development_dependency "vcr"
|
41
|
+
spec.add_development_dependency "webmock"
|
42
|
+
spec.add_development_dependency "prettier"
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,198 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: paymongo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Xavi Ablaza
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-11-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: gem_config
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry-byebug
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: vcr
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: webmock
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: prettier
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description:
|
140
|
+
email:
|
141
|
+
- dev@makisu.co
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- ".circleci/config.yml"
|
147
|
+
- ".github/workflows/gempush.yml"
|
148
|
+
- ".gitignore"
|
149
|
+
- ".rspec"
|
150
|
+
- ".travis.yml"
|
151
|
+
- CHANGELOG.md
|
152
|
+
- CODE_OF_CONDUCT.md
|
153
|
+
- Gemfile
|
154
|
+
- Gemfile.lock
|
155
|
+
- LICENSE.txt
|
156
|
+
- README.md
|
157
|
+
- Rakefile
|
158
|
+
- bin/console
|
159
|
+
- bin/setup
|
160
|
+
- lib/paymongo.rb
|
161
|
+
- lib/paymongo/base_module.rb
|
162
|
+
- lib/paymongo/configuration.rb
|
163
|
+
- lib/paymongo/error_result.rb
|
164
|
+
- lib/paymongo/exceptions.rb
|
165
|
+
- lib/paymongo/gateway.rb
|
166
|
+
- lib/paymongo/http.rb
|
167
|
+
- lib/paymongo/successful_result.rb
|
168
|
+
- lib/paymongo/transaction.rb
|
169
|
+
- lib/paymongo/transaction_gateway.rb
|
170
|
+
- lib/paymongo/version.rb
|
171
|
+
- paymongo.gemspec
|
172
|
+
homepage: https://github.com/makisu/paymongo
|
173
|
+
licenses:
|
174
|
+
- MIT
|
175
|
+
metadata:
|
176
|
+
homepage_uri: https://github.com/makisu/paymongo
|
177
|
+
source_code_uri: https://github.com/makisu/paymongoy
|
178
|
+
changelog_uri: https://github.com/makisu/paymongo/blob/master/CHANGELOG.md
|
179
|
+
post_install_message:
|
180
|
+
rdoc_options: []
|
181
|
+
require_paths:
|
182
|
+
- lib
|
183
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
189
|
+
requirements:
|
190
|
+
- - ">="
|
191
|
+
- !ruby/object:Gem::Version
|
192
|
+
version: '0'
|
193
|
+
requirements: []
|
194
|
+
rubygems_version: 3.0.3
|
195
|
+
signing_key:
|
196
|
+
specification_version: 4
|
197
|
+
summary: Charge credit cards using PayMongo in Ruby.
|
198
|
+
test_files: []
|