vivapayments 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +36 -0
- data/README.md +67 -0
- data/lib/vivapayments.rb +18 -0
- data/lib/vivapayments/configuration.rb +22 -0
- data/lib/vivapayments/order.rb +94 -0
- data/lib/vivapayments/version.rb +3 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/vivapayments/configuration_spec.rb +70 -0
- data/spec/vivapayments/order_spec.rb +61 -0
- data/vivapayments.gemspec +17 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NWNkNWQ2ZTZjOGU0NDI1MzllZTU5YjcxMzUxOTQ4NjI4MjY1MGVlNA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YzllOWY3YzllZDEyNTcwMzEwZmVkNmM5M2FkNTk5YTZmNTUzZmRkNg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MDJkYjM3MzkzYjllZTZmZGJmMTIwMDQ5NjA0YWEzMWMyM2Q3ZTc1YzhkZjA4
|
10
|
+
ZThmZjkxMzFjYjdiN2ZmYTFmM2UwMjY4YTUyYzExYzcwYmU5ZjcwNGVhODgx
|
11
|
+
ZTgwYzBjYTRjNmVlZjQ0NTBjMzlmODAzNTliMjFiYzMzMGJjMDI=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZjYwODg3YjQxMGJjYWZiZDYxNDc3ZWFhOTBlMGUxYTFhNDlhOTBiYjlkZmY1
|
14
|
+
MDU4ZWE3ZDUzZTk0NDY5NThlYmRlNWFmMTJkYjhhY2Q5NDk2NjQwMmJiM2My
|
15
|
+
ZmE2OWFiOTc4NzgyZTYyZjRmNmE1OTc1ZDUxNGNjZDA4ODg2NzM=
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
vivapayments (0.0.1)
|
5
|
+
faraday
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
coderay (1.1.0)
|
11
|
+
diff-lcs (1.2.5)
|
12
|
+
faraday (0.9.0)
|
13
|
+
multipart-post (>= 1.2, < 3)
|
14
|
+
method_source (0.8.2)
|
15
|
+
multipart-post (2.0.0)
|
16
|
+
pry (0.9.12.6)
|
17
|
+
coderay (~> 1.0)
|
18
|
+
method_source (~> 0.8)
|
19
|
+
slop (~> 3.4)
|
20
|
+
rspec (2.14.1)
|
21
|
+
rspec-core (~> 2.14.0)
|
22
|
+
rspec-expectations (~> 2.14.0)
|
23
|
+
rspec-mocks (~> 2.14.0)
|
24
|
+
rspec-core (2.14.8)
|
25
|
+
rspec-expectations (2.14.5)
|
26
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
27
|
+
rspec-mocks (2.14.6)
|
28
|
+
slop (3.4.7)
|
29
|
+
|
30
|
+
PLATFORMS
|
31
|
+
ruby
|
32
|
+
|
33
|
+
DEPENDENCIES
|
34
|
+
pry
|
35
|
+
rspec
|
36
|
+
vivapayments!
|
data/README.md
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# Vivapayments
|
2
|
+
|
3
|
+
Wrapper gem for the Vivapayments API. At the moment it supports creating an
|
4
|
+
order, deleting an order and getting the redirect URL to complete a
|
5
|
+
transaction.
|
6
|
+
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
### As part of a Gemfile in a Ruby application
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
gem 'vivapayments'
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle install
|
19
|
+
|
20
|
+
### Install the Gem individually
|
21
|
+
|
22
|
+
$ gem install vivapayments
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
Set up config (for example in `initializers/vivapayments.rb`):
|
27
|
+
|
28
|
+
Vivapayments.configure do |config|
|
29
|
+
config.merchant_id = "your_merchant_id"
|
30
|
+
config.api_key = "your_api_key"
|
31
|
+
config.demo = true # true or false
|
32
|
+
end
|
33
|
+
|
34
|
+
Creating an order:
|
35
|
+
|
36
|
+
order = Vivapayments::Order.new(:Amount => 100)
|
37
|
+
order.create
|
38
|
+
|
39
|
+
Getting the redirect_url:
|
40
|
+
|
41
|
+
order.redirect_url
|
42
|
+
|
43
|
+
Deleting an order (given that you have an id already):
|
44
|
+
|
45
|
+
order.delete
|
46
|
+
|
47
|
+
Or if you want to give an existing id:
|
48
|
+
|
49
|
+
order = Vivapayments::Order.new
|
50
|
+
order.id = 12345
|
51
|
+
order.delete
|
52
|
+
|
53
|
+
You can pass all the params that are mentioned in the documentation:
|
54
|
+
[https://github.com/VivaPayments/API/wiki/Optional-Parameters](https://github.com/VivaPayments/API/wiki/Optional-Parameters)
|
55
|
+
|
56
|
+
For more information on the documentation visit:
|
57
|
+
[https://github.com/VivaPayments/API/wiki](https://github.com/VivaPayments/API/wiki)
|
58
|
+
|
59
|
+
|
60
|
+
## Tests
|
61
|
+
|
62
|
+
MERCHANT_ID=your_merchant_id API_KEY=your_api_key rspec
|
63
|
+
|
64
|
+
At the moment it doesn't check the type of the variable for each parameter.
|
65
|
+
The API silently fails or ignores incorrect parameters, so be sure to check the
|
66
|
+
documentation about the correct input.
|
67
|
+
|
data/lib/vivapayments.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
require_relative "vivapayments/version"
|
5
|
+
require_relative "vivapayments/configuration"
|
6
|
+
require_relative "vivapayments/order"
|
7
|
+
|
8
|
+
module Vivapayments
|
9
|
+
attr_reader :configuration
|
10
|
+
|
11
|
+
def self.configure(&block)
|
12
|
+
yield configuration
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.configuration
|
16
|
+
@configuration ||= Configuration.new
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Vivapayments
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :api_key, :merchant_id, :demo
|
4
|
+
attr_reader :url, :api_url, :redirect_url
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@demo = true
|
8
|
+
end
|
9
|
+
|
10
|
+
def url
|
11
|
+
@url = demo ? "http://demo.vivapayments.com/" : "https://www.vivapayments.com/"
|
12
|
+
end
|
13
|
+
|
14
|
+
def api_url
|
15
|
+
@api_url = [url, "api/"].join
|
16
|
+
end
|
17
|
+
|
18
|
+
def redirect_url
|
19
|
+
@redirect_url = [url, "web/checkout"].join
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module Vivapayments
|
2
|
+
class Order
|
3
|
+
attr_reader :url, :connection, :id
|
4
|
+
attr_accessor :params
|
5
|
+
|
6
|
+
def initialize(params={})
|
7
|
+
@params = params
|
8
|
+
@connection = Faraday.new(:url => Vivapayments.configuration.api_url)
|
9
|
+
connection.basic_auth(Vivapayments.configuration.merchant_id, Vivapayments.configuration.api_key)
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
def id=(value)
|
14
|
+
@id = value
|
15
|
+
end
|
16
|
+
|
17
|
+
def create
|
18
|
+
raise ArgumentError, "`Amount` param is required." unless params.keys.map(&:to_sym).include?(:Amount)
|
19
|
+
|
20
|
+
valid_params?
|
21
|
+
|
22
|
+
content = connection.post("orders", params)
|
23
|
+
if content.status == 200 && JSON.parse(content.body)["ErrorCode"] == 0 && JSON.parse(content.body)["OrderCode"]
|
24
|
+
@id = JSON.parse(content.body)["OrderCode"]
|
25
|
+
else
|
26
|
+
raise "Status: #{content.status} - Message: #{content.body}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def delete
|
31
|
+
id_set?
|
32
|
+
|
33
|
+
content = connection.delete("orders/#{self.id}")
|
34
|
+
if content.status == 200
|
35
|
+
@id = nil
|
36
|
+
return content
|
37
|
+
else
|
38
|
+
raise "#{content.status} : #{JSON.parse(content.body)["Message"]}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def redirect_url
|
43
|
+
id_set?
|
44
|
+
[Vivapayments.configuration.redirect_url, "?ref=#{self.id}"].join
|
45
|
+
end
|
46
|
+
|
47
|
+
protected
|
48
|
+
|
49
|
+
def valid_params?
|
50
|
+
invalid_params = []
|
51
|
+
params.keys.each do |key|
|
52
|
+
invalid_params << key unless accepted_params.include?(key.to_sym)
|
53
|
+
end
|
54
|
+
|
55
|
+
unless invalid_params.empty?
|
56
|
+
raise ArgumentError, "params `#{invalid_params.join(",")}` are not valid. Accepted params: #{accepted_params.map(&:to_s).join(",")}"
|
57
|
+
else
|
58
|
+
return true
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
##
|
63
|
+
# To keep compatibility with the API, we use the params format given in
|
64
|
+
# the documentation.
|
65
|
+
#
|
66
|
+
def accepted_params
|
67
|
+
[
|
68
|
+
:Amount,
|
69
|
+
:isPreAuth,
|
70
|
+
:ServiceId,
|
71
|
+
:RequestLang,
|
72
|
+
:FullName,
|
73
|
+
:Email,
|
74
|
+
:Phone,
|
75
|
+
:MaxInstallments,
|
76
|
+
:MerchantTrns,
|
77
|
+
:CustomerTrns,
|
78
|
+
:SourceCode,
|
79
|
+
:PaymentTimeOut,
|
80
|
+
:ExpirationDate,
|
81
|
+
:AllowRecurring,
|
82
|
+
:Tags,
|
83
|
+
:AllowTaxCard,
|
84
|
+
:ActionUser,
|
85
|
+
:DisableCash,
|
86
|
+
:DisableCard
|
87
|
+
]
|
88
|
+
end
|
89
|
+
|
90
|
+
def id_set?
|
91
|
+
raise ArgumentError, "id is not set. Use `create` method or `id=` method." unless self.id
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'rspec'
|
3
|
+
|
4
|
+
require_relative '../lib/vivapayments'
|
5
|
+
|
6
|
+
Vivapayments.configure do |config|
|
7
|
+
config.api_key = "foo"
|
8
|
+
config.merchant_id = "bar"
|
9
|
+
config.demo = true
|
10
|
+
end
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.color = true
|
14
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Vivapayments::Configuration do
|
4
|
+
|
5
|
+
context 'returns correct api_url' do
|
6
|
+
|
7
|
+
example 'default environment is demo' do
|
8
|
+
Vivapayments.configuration.api_url.should == "http://demo.vivapayments.com/api/"
|
9
|
+
|
10
|
+
config = Vivapayments::Configuration.new
|
11
|
+
config.api_url.should == "http://demo.vivapayments.com/api/"
|
12
|
+
end
|
13
|
+
|
14
|
+
example 'production environment' do
|
15
|
+
Vivapayments.configure do |config|
|
16
|
+
config.demo = false
|
17
|
+
end
|
18
|
+
|
19
|
+
Vivapayments.configuration.api_url.should == "https://www.vivapayments.com/api/"
|
20
|
+
|
21
|
+
config = Vivapayments::Configuration.new
|
22
|
+
config.demo = false
|
23
|
+
config.api_url.should == "https://www.vivapayments.com/api/"
|
24
|
+
end
|
25
|
+
|
26
|
+
example 'demo environment' do
|
27
|
+
Vivapayments.configure do |config|
|
28
|
+
config.demo = true
|
29
|
+
end
|
30
|
+
|
31
|
+
Vivapayments.configuration.api_url.should == "http://demo.vivapayments.com/api/"
|
32
|
+
|
33
|
+
config = Vivapayments::Configuration.new
|
34
|
+
config.demo = true
|
35
|
+
config.api_url.should == "http://demo.vivapayments.com/api/"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'returns correct redirect_url' do
|
40
|
+
example 'demo environment' do
|
41
|
+
Vivapayments.configure do |config|
|
42
|
+
config.demo = true
|
43
|
+
end
|
44
|
+
Vivapayments.configuration.redirect_url.should == "http://demo.vivapayments.com/web/checkout"
|
45
|
+
|
46
|
+
config = Vivapayments::Configuration.new
|
47
|
+
config.redirect_url.should == "http://demo.vivapayments.com/web/checkout"
|
48
|
+
end
|
49
|
+
|
50
|
+
example 'production environment' do
|
51
|
+
Vivapayments.configure do |config|
|
52
|
+
config.demo = false
|
53
|
+
end
|
54
|
+
|
55
|
+
Vivapayments.configuration.redirect_url.should == "https://www.vivapayments.com/web/checkout"
|
56
|
+
|
57
|
+
config = Vivapayments::Configuration.new
|
58
|
+
config.demo = false
|
59
|
+
config.redirect_url.should == "https://www.vivapayments.com/web/checkout"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
example 'returns correct api_token' do
|
64
|
+
Vivapayments.configuration.api_key.should == "foo"
|
65
|
+
end
|
66
|
+
|
67
|
+
example 'returns correct merchant_id' do
|
68
|
+
Vivapayments.configuration.merchant_id.should == "bar"
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Vivapayments::Order do
|
4
|
+
|
5
|
+
context "set ENV['MERCHANT_ID'] and ENV['API_KEY'] for tests" do
|
6
|
+
before :all do
|
7
|
+
Vivapayments.configure do |config|
|
8
|
+
config.api_key = ENV['API_KEY']
|
9
|
+
config.merchant_id = ENV['MERCHANT_ID']
|
10
|
+
config.demo = true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
example 'raise ArgumentError if `Amount` param is missing' do
|
15
|
+
order = Vivapayments::Order.new
|
16
|
+
expect{ order.create}.to raise_error(ArgumentError, "`Amount` param is required.")
|
17
|
+
end
|
18
|
+
|
19
|
+
example 'raise ArgumentError if invalid param is given' do
|
20
|
+
order = Vivapayments::Order.new(:Amount => 100, :foo => "bar")
|
21
|
+
expect{ order.create}.to raise_error(ArgumentError)
|
22
|
+
end
|
23
|
+
|
24
|
+
example 'set id correctly' do
|
25
|
+
order = Vivapayments::Order.new
|
26
|
+
order.id = 101
|
27
|
+
order.id.should == 101
|
28
|
+
end
|
29
|
+
|
30
|
+
example 'get id from create' do
|
31
|
+
order = Vivapayments::Order.new(:Amount => 100)
|
32
|
+
order.create
|
33
|
+
order.id.is_a?(Fixnum).should == true
|
34
|
+
end
|
35
|
+
|
36
|
+
example 'raise ArgumentError if id is not set on delete' do
|
37
|
+
order = Vivapayments::Order.new
|
38
|
+
expect{ order.delete}.to raise_error(ArgumentError, "id is not set. Use `create` method or `id=` method.")
|
39
|
+
end
|
40
|
+
|
41
|
+
example 'return nil id after delete' do
|
42
|
+
order = Vivapayments::Order.new(:Amount => 100)
|
43
|
+
order.create
|
44
|
+
order.delete
|
45
|
+
order.id.should == nil
|
46
|
+
end
|
47
|
+
|
48
|
+
example 'return status 200 on successful delete' do
|
49
|
+
order = Vivapayments::Order.new(:Amount => 100)
|
50
|
+
order.create
|
51
|
+
res = order.delete
|
52
|
+
res.status.should == 200
|
53
|
+
end
|
54
|
+
|
55
|
+
example 'return correct redirect_url' do
|
56
|
+
order = Vivapayments::Order.new(:Amount => 100)
|
57
|
+
order.create
|
58
|
+
order.redirect_url.should == "http://demo.vivapayments.com/web/checkout?ref=#{order.id}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.expand_path('../lib/vivapayments/version', __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.name = 'vivapayments'
|
5
|
+
gem.version = Vivapayments::VERSION
|
6
|
+
gem.authors = ['Giannis Melidis']
|
7
|
+
gem.email = ['gmelidis@engineer.com']
|
8
|
+
gem.summary = 'Wrapper for the Vivapayments API.'
|
9
|
+
gem.description = gem.summary
|
10
|
+
gem.required_ruby_version = '>= 1.9.3'
|
11
|
+
|
12
|
+
gem.files = `git ls-files`.split("\n").sort
|
13
|
+
|
14
|
+
gem.add_dependency 'faraday'
|
15
|
+
gem.add_development_dependency 'rspec'
|
16
|
+
gem.add_development_dependency 'pry'
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vivapayments
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Giannis Melidis
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
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: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
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: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Wrapper for the Vivapayments API.
|
56
|
+
email:
|
57
|
+
- gmelidis@engineer.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- Gemfile
|
63
|
+
- Gemfile.lock
|
64
|
+
- README.md
|
65
|
+
- lib/vivapayments.rb
|
66
|
+
- lib/vivapayments/configuration.rb
|
67
|
+
- lib/vivapayments/order.rb
|
68
|
+
- lib/vivapayments/version.rb
|
69
|
+
- spec/spec_helper.rb
|
70
|
+
- spec/vivapayments/configuration_spec.rb
|
71
|
+
- spec/vivapayments/order_spec.rb
|
72
|
+
- vivapayments.gemspec
|
73
|
+
homepage:
|
74
|
+
licenses: []
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: 1.9.3
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.2.1
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Wrapper for the Vivapayments API.
|
96
|
+
test_files: []
|
97
|
+
has_rdoc:
|