payu_za 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
+ SHA1:
3
+ metadata.gz: f79cdfe7ab276c4aa7cdc7845567507ba5abe271
4
+ data.tar.gz: 8e19b1e54cca1952fe60dd8bbfc3dcd51a89fc49
5
+ SHA512:
6
+ metadata.gz: 9d770bc328474caf38da34f830de867ed05310b9822fc78d67d4a7b83e4dfeab8cf1702f5ecc5152438146f333fb2e171e90ae37ae739c0d8664aa256053cee8
7
+ data.tar.gz: ce12d5a2c97fd7f68f25f939b19d4939e2466a1ef71ff51b43d587c844dc3cb89525c9f7a01e5525d676844a009380112d91fa354a4b025c4f96f77523127c36
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in payu_za.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem 'guard-rspec', '~> 4.5.2'
8
+ gem 'pry-byebug'
9
+ end
data/Guardfile ADDED
@@ -0,0 +1,16 @@
1
+ guard :rspec, cmd: "bundle exec rspec" do
2
+ require "guard/rspec/dsl"
3
+ dsl = Guard::RSpec::Dsl.new(self)
4
+
5
+ # Feel free to open issues for suggestions and improvements
6
+
7
+ # RSpec files
8
+ rspec = dsl.rspec
9
+ watch(rspec.spec_helper) { rspec.spec_dir }
10
+ watch(rspec.spec_support) { rspec.spec_dir }
11
+ watch(rspec.spec_files)
12
+
13
+ # Ruby files
14
+ ruby = dsl.ruby
15
+ dsl.watch_spec_files_for(ruby.lib_files)
16
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Stan Bondi
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,91 @@
1
+ # PayuZa
2
+
3
+ PayU ZA Enterprise SOAP API integration
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'payu_za'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install payu_za
20
+
21
+ ## Usage
22
+
23
+ ### Initializer
24
+
25
+ ```ruby
26
+ PayUZa.configure do |c|
27
+ c.soap_username = ENV['PAYU_SOAP_USERNAME']
28
+ c.soap_password = ENV['PAYU_SOAP_PASSWORD']
29
+ c.safe_key = ENV['PAYU_SAFE_KEY']
30
+ # Be sure to set your environment to :production in prod - defaults to :staging
31
+ c.environment = :production # or :staging or Rails.env.to_sym
32
+
33
+ # Other configuration
34
+ # Set the default api version (can be overriden per request)
35
+ # c.api_version = "ONE_ZERO"
36
+ #
37
+ # Set password_digest to true to prevent your password being sent in clear text
38
+ # Defaults to false because not sure if PayU supports wsse password digest
39
+ # c.password_digest = true
40
+ #
41
+ # Set your own wsdls - not sure why anyone would ever need this
42
+ # c.wsdl_endpoints = {
43
+ # development: 'https://localhost:12345/?wsdl',
44
+ # production: 'https://my-proxy.com/wsdl'
45
+ # }
46
+ end
47
+ ```
48
+
49
+ ### DoTransaction Example
50
+
51
+ ```ruby
52
+ client = PayUZa::Client.new
53
+
54
+ additional_info = client.new_struct(:additional_information, {
55
+ merchantReference: '12345',
56
+ payUReference: 'abcdefg1234'
57
+ })
58
+
59
+ transaction = client.new_struct(:do_transaction, {
60
+ TransactionType: PayUZa::Structs::TRANSACTION_TYPE::PAYMENT,
61
+ AuthenticationType: PayUZa::Structs::AUTHENTICATION_TYPE::NA,
62
+ AdditionalInformation: additional_info
63
+ # etc ...
64
+ })
65
+
66
+ # Object style
67
+ creditcard = client.new_struct(:credit_card)
68
+ creditcard.cardNumber = '4242424242424242'
69
+ creditcard.cardExpiry = '122013'
70
+
71
+ transaction.Creditcard = creditcard
72
+
73
+ response = client.execute(transaction)
74
+ # or you can pass in a hash
75
+ response = client.execute(:do_transaction, {
76
+ Api: 'ONE_ZERO',
77
+ SafeKey: '12345'
78
+ # ...
79
+ })
80
+
81
+ ```
82
+
83
+ Supports `do_transaction`, `set_transaction` and `get_transaction`
84
+
85
+ ## Contributing
86
+
87
+ 1. Fork it ( https://github.com/fixate/payu_za/fork )
88
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
89
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
90
+ 4. Push to the branch (`git push origin my-new-feature`)
91
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,45 @@
1
+ module PayuZa
2
+ class Client
3
+ def operations
4
+ client.operations
5
+ end
6
+
7
+ # execute(:method, {my: 'message'}|Struct)
8
+ # or
9
+ # execute(Struct)
10
+ def execute(*args)
11
+ if args.length > 1
12
+ operation_name, struct = args
13
+ else
14
+ struct = args.first
15
+ operation_name = struct.operation_name
16
+ end
17
+
18
+ message = struct.respond_to?(:to_hash) ? struct.to_hash : struct
19
+
20
+ client.call(operation_name, message: message)
21
+ end
22
+
23
+ def new_struct(name, attributes = {})
24
+ klass = name.to_s.camelize
25
+ "PayuZa::Structs::#{klass}".constantize.create(attributes)
26
+ end
27
+
28
+ def request(name, struct)
29
+ client.operation(name).request(message: struct.to_hash)
30
+ end
31
+
32
+ def client
33
+ @client ||= Savon.client(
34
+ wsdl: PayuZa.wsdl_endpoint,
35
+ wsse_auth: wsse_auth
36
+ )
37
+ end
38
+
39
+ private
40
+
41
+ def wsse_auth
42
+ [PayuZa.soap_username, PayuZa.soap_password, PayuZa.password_digest]
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,10 @@
1
+ module PayuZa
2
+ class StructNotValidError < StandardError
3
+ attr_reader :var_name
4
+
5
+ def initialize(var_name, message)
6
+ @message = "#{var_name} #{message}"
7
+ @var_name = var_name
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,12 @@
1
+ module PayuZa
2
+ module Structs
3
+ class AdditionalInformation
4
+ include StructModel
5
+
6
+ field :merchantReference, required: true
7
+ field :payUReference
8
+ field :demoMode
9
+ field :notificationUrl
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ module PayuZa
2
+ module Structs
3
+ class Basket
4
+ include StructModel
5
+
6
+ field :description, required: true
7
+ field :amountInCents, required: true
8
+ field :currencyCode, required: true
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ module PayuZa
2
+ module Structs
3
+ class CreditCard
4
+ include StructModel
5
+
6
+ field :pmId
7
+ field :cardNumber
8
+ field :cardExpiry
9
+ field :cvv
10
+ field :nameOnCard
11
+ field :budgetPeriod
12
+ field :amountInCents, required: true
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ module PayuZa
2
+ module Structs
3
+ class CustomField
4
+ include StructModel
5
+
6
+ field :key, required: true
7
+ field :value, default: ''
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,15 @@
1
+ module PayuZa
2
+ module Structs
3
+ class Customer
4
+ include StructModel
5
+
6
+ field :firstName
7
+ field :lastName
8
+ field :regionalId
9
+ field :mobile
10
+ field :email
11
+ field :merchantUserId
12
+ field :DOB
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ module PayuZa
2
+ module Structs
3
+ class DoTransaction < Transaction; end
4
+ end
5
+ end
@@ -0,0 +1,12 @@
1
+ module PayuZa
2
+ module Structs
3
+ class GetTransaction
4
+ include StructModel
5
+
6
+ field :Api, default: 'ONE_ZERO'
7
+ field :SafeKey, default: -> { PayuZa.safe_key }
8
+ field :payUReference
9
+ field :merchantReference
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ module PayuZa
2
+ module Structs
3
+ class SetTransaction < Transaction; end
4
+ end
5
+ end
@@ -0,0 +1,89 @@
1
+ module PayuZa
2
+ module Structs
3
+ module StructModel
4
+
5
+ def self.included(base)
6
+ base.send(:extend, ClassMethods)
7
+ end
8
+
9
+ def valid?
10
+ validate! rescue false
11
+ end
12
+
13
+ def validate!
14
+ self.class.fields.each do |name, options|
15
+ if options[:required] && send(name).nil?
16
+ raise StructNotValidError.new(name, 'is required')
17
+ end
18
+ end
19
+ end
20
+
21
+ def to_hash
22
+ vars_to_hash
23
+ end
24
+
25
+ def operation_name
26
+ @operation_name ||= self.class.name.split('::').last.underscore.to_sym
27
+ end
28
+
29
+ private
30
+
31
+ def vars_to_hash
32
+ hash = {}
33
+ self.class.fields.each do |name, _options|
34
+ value = send(name)
35
+ next if value.nil?
36
+ hash[name.to_s] = hash_value(value)
37
+ end
38
+ hash
39
+ end
40
+
41
+ def hash_value(value)
42
+ if value.respond_to?(:to_hash)
43
+ value.to_hash
44
+ elsif value.is_a?(Array)
45
+ value.map do |v|
46
+ hash_value(v)
47
+ end
48
+ else
49
+ value
50
+ end
51
+ end
52
+
53
+ def default_for(field)
54
+ default = self.class.fields[field][:default]
55
+ if default.respond_to?(:call)
56
+ default.arity > 0 ? default.call(self) : default.call
57
+ else
58
+ default
59
+ end
60
+ end
61
+
62
+ module ClassMethods
63
+ def field(name, options = {})
64
+ fields[name] = options
65
+
66
+ define_method name do
67
+ instance_variable_get(:"@#{name}") || default_for(name)
68
+ end
69
+
70
+ define_method "#{name}=" do |value|
71
+ instance_variable_set(:"@#{name}", value)
72
+ end
73
+ end
74
+
75
+ def create(attributes)
76
+ new.tap do |struct|
77
+ attributes.each do |name, value|
78
+ struct.send("#{name}=", value)
79
+ end
80
+ end
81
+ end
82
+
83
+ def fields
84
+ @fields ||= {}
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,18 @@
1
+ module PayuZa
2
+ module Structs
3
+ class Transaction
4
+ include StructModel
5
+
6
+ field :Api, default: 'ONE_ZERO'
7
+ field :SafeKey, default: -> { PayuZa.safe_key }
8
+ field :TransactionType, required: true
9
+ field :AuthenticationType, required: true
10
+ field :storePaymentMethod
11
+ field :AdditionalInformation, required: true
12
+ field :Basket, required: true
13
+ field :Customer
14
+ field :Creditcard
15
+ field :Loyalty
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,30 @@
1
+ require "payu_za/structs/struct_model"
2
+ require "payu_za/structs/additional_information"
3
+ require "payu_za/structs/customer"
4
+ require "payu_za/structs/credit_card"
5
+ require "payu_za/structs/basket"
6
+ require "payu_za/structs/custom_field"
7
+
8
+ require "payu_za/structs/transaction"
9
+ require "payu_za/structs/get_transaction"
10
+ require "payu_za/structs/set_transaction"
11
+ require "payu_za/structs/do_transaction"
12
+
13
+
14
+ module PayuZa
15
+ module Structs
16
+ module TRANSACTION_TYPE
17
+ RESERVE = 'RESERVE'
18
+ RESERVE_CANCEL = 'RESERVE_CANCEL'
19
+ PAYMENT = 'PAYMENT'
20
+ FINALIZE = 'FINALIZE'
21
+ CREDIT = 'CREDIT'
22
+ end
23
+
24
+ module AUTHENTICATION_TYPE
25
+ NA = 'NA'
26
+ HANDSHAKE = 'HANDSHAKE'
27
+ TOKEN = 'TOKEN'
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module PayuZa
2
+ VERSION = "0.0.1"
3
+ end
data/lib/payu_za.rb ADDED
@@ -0,0 +1,38 @@
1
+ require "active_support/core_ext/string"
2
+ require 'savon'
3
+
4
+ require "payu_za/version"
5
+ require "payu_za/errors"
6
+ require "payu_za/client"
7
+ require "payu_za/structs"
8
+
9
+ module PayuZa
10
+ extend self
11
+
12
+ attr_accessor :wsdl_endpoints, :environment, :soap_username, :soap_password,
13
+ :safe_key, :api_version, :password_digest
14
+
15
+ def configure
16
+ yield self
17
+ end
18
+
19
+ def default!
20
+ PayuZa.configure do |config|
21
+ config.api_version = 'ONE_ZERO'
22
+ config.wsdl_endpoints = {
23
+ development: 'https://staging.payu.co.za/service/PayUAPI?wsdl',
24
+ staging: 'https://staging.payu.co.za/service/PayUAPI?wsdl',
25
+ production: 'https://secure.payu.co.za/service/PayUAPI?wsdl'
26
+ }
27
+
28
+ config.environment = :staging
29
+ end
30
+ end
31
+
32
+ # Set defaults
33
+ default!
34
+
35
+ def wsdl_endpoint
36
+ wsdl_endpoints[environment]
37
+ end
38
+ end
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: payu_za
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Stan Bondi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: savon
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.11'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
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.3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.21'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.21'
97
+ description: |2
98
+ PayU ZA Enterprise SOAP Api integration
99
+
100
+ Provides an easy-to-use ruby to the tricky SOAP api.
101
+ email:
102
+ - stan@fixate.it
103
+ executables: []
104
+ extensions: []
105
+ extra_rdoc_files: []
106
+ files:
107
+ - Gemfile
108
+ - Guardfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - lib/payu_za.rb
113
+ - lib/payu_za/client.rb
114
+ - lib/payu_za/errors.rb
115
+ - lib/payu_za/structs.rb
116
+ - lib/payu_za/structs/additional_information.rb
117
+ - lib/payu_za/structs/basket.rb
118
+ - lib/payu_za/structs/credit_card.rb
119
+ - lib/payu_za/structs/custom_field.rb
120
+ - lib/payu_za/structs/customer.rb
121
+ - lib/payu_za/structs/do_transaction.rb
122
+ - lib/payu_za/structs/get_transaction.rb
123
+ - lib/payu_za/structs/set_transaction.rb
124
+ - lib/payu_za/structs/struct_model.rb
125
+ - lib/payu_za/structs/transaction.rb
126
+ - lib/payu_za/version.rb
127
+ homepage: https://github.com/fixate/payu_za
128
+ licenses:
129
+ - MIT
130
+ metadata: {}
131
+ post_install_message:
132
+ rdoc_options: []
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ requirements: []
146
+ rubyforge_project:
147
+ rubygems_version: 2.4.5
148
+ signing_key:
149
+ specification_version: 4
150
+ summary: PayU ZA Enterprise SOAP API integration
151
+ test_files: []