payoneer-ruby 0.1.0

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
+ SHA1:
3
+ metadata.gz: 988a5c0a2f12c8219f953c5ecdbf2088d81a67bc
4
+ data.tar.gz: 89d4cbe6d5b5002c4b30f6230e8d128d843170fb
5
+ SHA512:
6
+ metadata.gz: 087a2159e56f333de854a1b59c69ccef349b9b1c8bcee3f2fc856faaa262c6b0e790e19171a300acfa900b5e1a34c7f9d44eea27c3bab88d75dda6bbc14682ed
7
+ data.tar.gz: bc66c7806d5601c489a11c692efee63bb2ab7bcaa594a9bbe274dfcb5117fab2976a40825dd1da60aea79232cd87195aaa9fb9dc87c544b58abb0c136610a41e
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in payoneer-ruby.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Teespring
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,39 @@
1
+ # Payoneer::Ruby
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/payoneer/ruby`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'payoneer-ruby'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install payoneer-ruby
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( https://github.com/[my-github-username]/payoneer-ruby/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "payoneer-ruby"
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
+ require "pry"
10
+ Pry.start
@@ -0,0 +1,22 @@
1
+ module Payoneer
2
+ class Configuration
3
+ DEVELOPMENT_ENVIRONMENT = 'development'
4
+ PRODUCTION_ENVIRONMENT = 'production'
5
+ DEVELOPMENT_API_URL = 'https://api.sandbox.payoneer.com/Payouts/HttpApi/API.aspx?'
6
+ PRODUCTION_API_URL = 'https://api.payoneer.com/Payouts/HttpApi/API.aspx?'
7
+
8
+ attr_accessor :environment, :partner_id, :partner_username, :partner_api_password
9
+
10
+ def initialize
11
+ @environment = DEVELOPMENT_ENVIRONMENT
12
+ end
13
+
14
+ def api_url
15
+ environment == PRODUCTION_ENVIRONMENT ? PRODUCTION_API_URL : DEVELOPMENT_API_URL
16
+ end
17
+
18
+ def validate!
19
+ fail Errors::ConfigurationError unless partner_id && partner_username && partner_api_password
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,9 @@
1
+ module Payoneer
2
+ module Errors
3
+ class ConfigurationError < StandardError
4
+ def initialize
5
+ super 'Not all config vars were set. Payoneer requires partner_id, partner_username, and partner_api_password.'
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ module Payoneer
2
+ module Errors
3
+ class UnexpectedResponseError < StandardError
4
+ attr_reader :http_status
5
+ attr_reader :http_body
6
+
7
+ def initialize(http_status = nil, http_body = nil)
8
+ @http_status = http_status
9
+ @http_body = http_body
10
+ end
11
+
12
+ def to_s
13
+ "(Status #{http_status}) Unexpected http response code"
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,31 @@
1
+ require 'uri'
2
+
3
+ module Payoneer
4
+ class Payee
5
+ SIGNUP_URL_API_METHOD_NAME = 'GetToken'
6
+
7
+ def self.signup_url(payee_id, redirect_url: nil, redirect_time: nil)
8
+ payoneer_params = {
9
+ p4: payee_id,
10
+ p6: redirect_url,
11
+ p8: redirect_time,
12
+ p10: true, #returns an xml response
13
+ }
14
+
15
+ response = Payoneer.make_api_request(SIGNUP_URL_API_METHOD_NAME, payoneer_params)
16
+
17
+ if success?(response)
18
+ Response.new_ok_response(response['Token'])
19
+ else
20
+ Response.new(response['Code'], response['Description'])
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def self.success?(response)
27
+ !response.has_key?('Code')
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,21 @@
1
+ module Payoneer
2
+ class Payout
3
+ CREATE_PAYOUT_API_METHOD_NAME = 'PerformPayoutPayment'
4
+
5
+ def self.create(program_id:, payment_id:, payee_id:, amount:, description:, payment_date: Time.now, currency: 'USD')
6
+ payoneer_params = {
7
+ p4: program_id,
8
+ p5: payment_id,
9
+ p6: payee_id,
10
+ p7: '%.2f' % amount,
11
+ p8: description,
12
+ p9: payment_date.strftime('%m/%d/%Y %H:%M:%S'),
13
+ Currency: currency,
14
+ }
15
+
16
+ response = Payoneer.make_api_request(CREATE_PAYOUT_API_METHOD_NAME, payoneer_params)
17
+
18
+ Response.new(response['Status'], response['Description'])
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,24 @@
1
+ module Payoneer
2
+ class Response
3
+ attr_reader :code, :body
4
+
5
+ OK_STATUS_CODE = '000'
6
+
7
+ def self.new_ok_response(body)
8
+ new(OK_STATUS_CODE, body)
9
+ end
10
+
11
+ def initialize(code, body)
12
+ @code = code
13
+ @body = body
14
+ end
15
+
16
+ def ok?
17
+ code == OK_STATUS_CODE
18
+ end
19
+
20
+ def ==(other)
21
+ code == other.code && body == other.body
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,10 @@
1
+ module Payoneer
2
+ class System
3
+ STATUS_METHOD_NAME = 'Echo'
4
+
5
+ def self.status
6
+ resp = Payoneer.make_api_request(STATUS_METHOD_NAME)
7
+ Response.new(resp['Status'], resp['Description'])
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module Payoneer
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + '/payoneer'
data/lib/payoneer.rb ADDED
@@ -0,0 +1,59 @@
1
+ #Payoneer Ruby bindings
2
+ #API spec at https://github.com/teespring/payoneer-ruby
3
+ require 'rest-client'
4
+ require 'active_support'
5
+ require 'active_support/core_ext'
6
+
7
+ # Version
8
+ require 'payoneer/version'
9
+
10
+ # Configuration
11
+ require 'payoneer/configuration'
12
+
13
+ # Resources
14
+ require 'payoneer/response'
15
+ require 'payoneer/system'
16
+ require 'payoneer/payee'
17
+ require 'payoneer/payout'
18
+
19
+ # Errors
20
+ require 'payoneer/errors/unexpected_response_error'
21
+ require 'payoneer/errors/configuration_error'
22
+
23
+ module Payoneer
24
+ class << self
25
+ attr_accessor :configuration
26
+ end
27
+
28
+ def self.configure
29
+ yield(_configuration)
30
+ end
31
+
32
+ def self.make_api_request(method_name, params = {})
33
+ _configuration.validate!
34
+
35
+ request_params = default_params.merge(mname: method_name).merge(params)
36
+
37
+ response = RestClient.post(_configuration.api_url, request_params)
38
+
39
+ fail Errors::UnexpectedResponseError.new(response.code, response.body) unless response.code == 200
40
+
41
+ hash_response = Hash.from_xml(response.body)
42
+ inner_content = hash_response.values.first
43
+ inner_content
44
+ end
45
+
46
+ private
47
+
48
+ def self._configuration
49
+ self.configuration ||= Configuration.new
50
+ end
51
+
52
+ def self.default_params
53
+ {
54
+ p1: _configuration.partner_username,
55
+ p2: _configuration.partner_api_password,
56
+ p3: _configuration.partner_id,
57
+ }
58
+ end
59
+ end
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'payoneer/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'payoneer-ruby'
8
+ spec.version = Payoneer::VERSION
9
+ spec.authors = ['Tieshun Roquerre', 'Spencer Bell']
10
+ spec.email = ['tieshun@teespring.com', 'spencer@teespring.com']
11
+
12
+ spec.summary = 'Ruby bindings for the Payoneer API'
13
+ spec.description = 'Payoneer provides businesses with international money transfer services and global payments'
14
+ spec.homepage = 'https://github.com/teespring/payoneer-ruby'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.required_ruby_version = '~> 2.0'
23
+
24
+ spec.add_dependency 'rest-client'
25
+ spec.add_dependency 'activesupport'
26
+
27
+ spec.add_development_dependency 'rspec'
28
+ spec.add_development_dependency 'pry'
29
+ spec.add_development_dependency 'webmock'
30
+
31
+ spec.add_development_dependency 'bundler', '~> 1.7'
32
+ spec.add_development_dependency 'rake', '~> 10.0'
33
+ end
metadata ADDED
@@ -0,0 +1,164 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: payoneer-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tieshun Roquerre
8
+ - Spencer Bell
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2015-05-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rest-client
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: activesupport
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: pry
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: webmock
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: bundler
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '1.7'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '1.7'
98
+ - !ruby/object:Gem::Dependency
99
+ name: rake
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: '10.0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '10.0'
112
+ description: Payoneer provides businesses with international money transfer services
113
+ and global payments
114
+ email:
115
+ - tieshun@teespring.com
116
+ - spencer@teespring.com
117
+ executables: []
118
+ extensions: []
119
+ extra_rdoc_files: []
120
+ files:
121
+ - ".gitignore"
122
+ - ".rspec"
123
+ - ".ruby-version"
124
+ - Gemfile
125
+ - LICENSE.txt
126
+ - README.md
127
+ - Rakefile
128
+ - bin/console
129
+ - lib/payoneer-ruby.rb
130
+ - lib/payoneer.rb
131
+ - lib/payoneer/configuration.rb
132
+ - lib/payoneer/errors/configuration_error.rb
133
+ - lib/payoneer/errors/unexpected_response_error.rb
134
+ - lib/payoneer/payee.rb
135
+ - lib/payoneer/payout.rb
136
+ - lib/payoneer/response.rb
137
+ - lib/payoneer/system.rb
138
+ - lib/payoneer/version.rb
139
+ - payoneer-ruby.gemspec
140
+ homepage: https://github.com/teespring/payoneer-ruby
141
+ licenses:
142
+ - MIT
143
+ metadata: {}
144
+ post_install_message:
145
+ rdoc_options: []
146
+ require_paths:
147
+ - lib
148
+ required_ruby_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '2.0'
153
+ required_rubygems_version: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ requirements: []
159
+ rubyforge_project:
160
+ rubygems_version: 2.4.6
161
+ signing_key:
162
+ specification_version: 4
163
+ summary: Ruby bindings for the Payoneer API
164
+ test_files: []