ruby-gpwebpay 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: 0536ecb57b136380a6c1662e93b0cec5439bd59c655fa524a82ac14c0ac33117
4
+ data.tar.gz: 325be4295cd941abffa4d5e7569572fe8f93de3799f2a529bb2f5f85228b2540
5
+ SHA512:
6
+ metadata.gz: dcb7675ac86150be1b9c25c631b15d7176ceae25cb07da9dedf06a55fd2684478b728ee5c010179f28df5cdce13fac763373d30d9cca99fed821970b34fe7527
7
+ data.tar.gz: 8d50edcae500961cd41a30ce7698cdc1b2772391a928841a379803c32f12148a3729eb281af3cbcbe04ded9b0616c17d49d87866e8fba3dbc30d4cc6768239ed
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ .ruby-version
12
+
13
+ .ruby-gemset
14
+
15
+ .rspec_status
16
+
17
+ /bin/test_console
18
+ /bin/inboxcoffee.pem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.ruby_gemset ADDED
@@ -0,0 +1 @@
1
+ gpwebpay
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ dist: xenial
3
+ os: linux
4
+ rvm:
5
+ - 2.4.3
6
+ - 2.6.2
7
+ - 3.0.0
8
+ before_install:
9
+ - export TZ=Europe/Prague
10
+ - gem install bundler
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gp_webpay.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,111 @@
1
+ # GpWebpay
2
+
3
+ [![Build Status](https://travis-ci.org/redrick/gpwebpay.svg?branch=master)](https://travis-ci.org/redrick/gpwebpay)
4
+
5
+ Started as [this fork](https://github.com/redrick/gp_webpay) of https://github.com/blueberryapps/gp_webpay, Thanks for that one ;)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'gpwebpay'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install gpwebpay
22
+
23
+ ## Usage
24
+
25
+ Generate own certificate, put into your repository.
26
+
27
+ ### Initialize
28
+
29
+ config/initializers/gpwebpay.rb
30
+
31
+ ```ruby
32
+ GpWebpay.configure do |config|
33
+ config.merchant_number = ##########
34
+ config.merchant_pem_path = 'my_cert.pem'
35
+ config.merchant_password = 'password'
36
+ end
37
+ ```
38
+
39
+ ### Payment
40
+
41
+ ```ruby
42
+ class Payment
43
+ include GpWebpay::Payment
44
+
45
+ def order_number
46
+ id
47
+ end
48
+
49
+ def amount_in_cents
50
+ 100
51
+ end
52
+
53
+ ##
54
+ # implement this method if multiple types of payments required, otherwise default to normal one-time payment
55
+ #
56
+ # allows for 2 types:
57
+ # default -> normal one-time payment
58
+ # recurring -> master + recurring payments
59
+ ##
60
+ def payment_type
61
+ case variable
62
+ when one
63
+ return 'master'
64
+ when two
65
+ return 'recurring'
66
+ else
67
+ 'default'
68
+ end
69
+ end
70
+
71
+ def currency
72
+ 840 # CZK = 203, EUR = 978, GBP = 826, HUF = 348, PLN = 985, RUB = 643, USD = 840
73
+ end
74
+ end
75
+ ```
76
+
77
+ ### Controller
78
+ ```ruby
79
+ class OrdersController
80
+ def create
81
+ ...
82
+ payment = Payment.create
83
+ redirect_to payment.pay_url(redirect_url: 'http://example.com/orders/callback')
84
+ end
85
+
86
+ def callback
87
+ ...
88
+ payment = Payment.find(params['ORDERNUMBER'])
89
+ if payment.success?(params)
90
+ # Payment success
91
+ else
92
+ # Payment failed
93
+ # params['PRCODE'], params['SRCODE']
94
+ end
95
+ end
96
+ end
97
+ ```
98
+
99
+ ## Development
100
+
101
+ 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.
102
+
103
+ 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).
104
+
105
+ ## Contributing
106
+
107
+ 1. Fork it ( https://github.com/[my-github-username]/gpwebpay/fork )
108
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
109
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
110
+ 4. Push to the branch (`git push origin my-new-feature`)
111
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "gp_webpay"
5
+
6
+ require "pry"
7
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,20 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDLzCCAhegAwIBAgIBAjANBgkqhkiG9w0BAQUFADBNMRgwFgYDVQQDEw9NZXNz
3
+ YWdlIFNpZ25pbmcxEDAOBgNVBAsTB1BheU1VWk8xEjAQBgNVBAoTCU1VWk8sYS5z
4
+ LjELMAkGA1UEBhMCQ1owHhcNMDQwNjExMTAyMzU5WhcNMTQwNzI5MTAyMzU5WjBN
5
+ MRgwFgYDVQQDEw9NZXNzYWdlIFNpZ25pbmcxEDAOBgNVBAsTB1BheU1VWk8xEjAQ
6
+ BgNVBAoTCU1VWk8sYS5zLjELMAkGA1UEBhMCQ1owggEiMA0GCSqGSIb3DQEBAQ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-0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gp_webpay/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ruby-gpwebpay"
8
+ spec.version = GpWebpay::VERSION
9
+ spec.authors = ["Andrej Antas"]
10
+ spec.email = ["andrej@antas.cz"]
11
+
12
+ spec.summary = %q{GP webpay, payments, SOAP, payment gateway}
13
+ spec.homepage = "https://github.com/redrick/gpwebpay"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency 'activesupport'
22
+ spec.add_runtime_dependency 'nokogiri'
23
+ spec.add_runtime_dependency 'curb'
24
+
25
+ spec.add_development_dependency "bundler", "~> 2.2"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ spec.add_development_dependency 'simplecov', '~> 0.14'
29
+ spec.add_development_dependency 'vcr', '~> 3.0'
30
+ spec.add_development_dependency 'webmock', '~> 3.0'
31
+ spec.add_development_dependency 'pry'
32
+ spec.add_development_dependency 'wasabi'
33
+ spec.add_development_dependency 'libxml-ruby'
34
+ spec.add_development_dependency 'timecop'
35
+ end
data/lib/gp_webpay.rb ADDED
@@ -0,0 +1,9 @@
1
+ require "gp_webpay/config"
2
+ require "gp_webpay/payment_attributes"
3
+ require "gp_webpay/payment"
4
+ require "gp_webpay/version"
5
+ require "gp_webpay/verification"
6
+ require "gp_webpay/web_services"
7
+
8
+ module GpWebpay
9
+ end
@@ -0,0 +1,64 @@
1
+ require "active_support/configurable"
2
+
3
+ module GpWebpay
4
+ # Configures global settings for Kaminari
5
+ # GpWebpay.configure do |config|
6
+ # config.default_per_page = 10
7
+ # end
8
+ def self.configure(&block)
9
+ yield @config ||= GpWebpay::Configuration.new
10
+ end
11
+
12
+ # Global settings for Kaminari
13
+ def self.config
14
+ @config
15
+ end
16
+
17
+ # need a Class for 3.0
18
+ class Configuration #:nodoc:
19
+ include ActiveSupport::Configurable
20
+ config_accessor :merchant_number do nil; end
21
+ config_accessor :merchant_pem do nil; end
22
+ config_accessor :merchant_pem_path do nil; end
23
+ config_accessor :merchant_password do nil; end
24
+ config_accessor :gpe_pem_path do nil; end
25
+ config_accessor :environment do
26
+ defined?(Rails) && Rails.env || "test"
27
+ end
28
+
29
+ def param_name
30
+ config.param_name.respond_to?(:call) ? config.param_name.call : config.param_name
31
+ end
32
+
33
+ def pay_url
34
+ if production?
35
+ "https://3dsecure.gpwebpay.com/kb/order.do"
36
+ else
37
+ "https://test.3dsecure.gpwebpay.com/kb/order.do"
38
+ end
39
+ end
40
+
41
+ def web_services_url
42
+ if production?
43
+ "https://3dsecure.gpwebpay.com/pay-ws/v1/PaymentService"
44
+ else
45
+ "https://test.3dsecure.gpwebpay.com/pay-ws/v1/PaymentService"
46
+ end
47
+ end
48
+
49
+ def gpe_pem_path
50
+ file_name = production? ? "muzo.signing_prod.pem" : "muzo.signing_test.pem"
51
+
52
+ File.expand_path("../../../certs/#{file_name}", __FILE__)
53
+ end
54
+
55
+ def production?
56
+ config.environment == "production"
57
+ end
58
+
59
+ # define param_name writer (copied from AS::Configurable)
60
+ writer, line = "def param_name=(value); config.param_name = value; end", __LINE__
61
+ singleton_class.class_eval writer, __FILE__, line
62
+ class_eval writer, __FILE__, line
63
+ end
64
+ end
@@ -0,0 +1,58 @@
1
+ module GpWebpay
2
+ module Payment
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ attr_accessor :redirect_url
7
+ end
8
+
9
+ def deposit_flag
10
+ 1
11
+ end
12
+
13
+ def user_param
14
+ "R"
15
+ end
16
+
17
+ def payment_type
18
+ super || "default"
19
+ end
20
+
21
+ def merchant_number
22
+ config.merchant_number
23
+ end
24
+
25
+ def operation
26
+ "CREATE_ORDER"
27
+ end
28
+
29
+ def pay_url(options = {})
30
+ self.redirect_url = options[:redirect_url]
31
+
32
+ "#{config.pay_url}?#{pay_verification.payment_attributes_with_digest.to_param}"
33
+ end
34
+
35
+ def success?(params)
36
+ pay_verification.verified_response?(params) &&
37
+ params["PRCODE"] == "0" && params["SRCODE"] == "0"
38
+ end
39
+
40
+ private
41
+
42
+ def pay_verification_attrs
43
+ %i(operation order_number prcode srcode resulttext)
44
+ end
45
+
46
+ def pay_attributes
47
+ @pay_attributes ||= PaymentAttributes.new(self).to_h
48
+ end
49
+
50
+ def config
51
+ GpWebpay.config
52
+ end
53
+
54
+ def pay_verification
55
+ ::GpWebpay::Verification.new(pay_attributes, pay_verification_attrs)
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,58 @@
1
+ module GpWebpay
2
+ class PaymentAttributes
3
+ KEYS = %i(merchant_number operation order_number amount_in_cents currency deposit_flag redirect_url description merchant_description user_param)
4
+
5
+ WS_KEYS = %i(message_id bank_id merchant_number order_number)
6
+
7
+ REGULAR_PAYMENT_KEYS = %i(
8
+ message_id bank_id merchant_number order_number master_order_number merchant_order_number amount_in_cents capture_flag
9
+ card_holder.name card_holder.email card_holder.phone_country card_holder.phone card_holder.mobile_phone_country card_holder.mobile_phone
10
+ address_match
11
+ billing.name billing.address1 billing.city billing.postal_code billing.country
12
+ shipping.name shipping.address1 shipping.city shipping.postal_code shipping.country
13
+ )
14
+
15
+ OPTIONAL_KEYS = %i(merchant_order_number description merchant_description)
16
+
17
+ MASTER_KEYS = %i(user_param)
18
+
19
+ def initialize(payment, ws_flag = false, type = "")
20
+ @payment = payment
21
+ @ws_flag = ws_flag
22
+ @type = type
23
+ end
24
+
25
+ def keys
26
+ case @payment.payment_type
27
+ when "master"
28
+ return (@ws_flag ? WS_KEYS : KEYS)
29
+ when "recurring"
30
+ case @type
31
+ when "processRegularSubscriptionPayment"
32
+ return REGULAR_PAYMENT_KEYS
33
+ else
34
+ return WS_KEYS
35
+ end
36
+ else
37
+ return KEYS.reject { |k| MASTER_KEYS.include?(k) }
38
+ end
39
+ end
40
+
41
+ def to_h
42
+ keys.each_with_object({}) do |method, hash|
43
+ method_chain = method.to_s.split(".").map(&:to_sym)
44
+ if @payment.respond_to?(*method_chain)
45
+ if method == :message_id
46
+ hash[method] = @payment.public_send(method, @type)
47
+ else
48
+ hash[method] = method_chain.inject(@payment, :public_send)
49
+ end
50
+ elsif !OPTIONAL_KEYS.include?(method)
51
+ method_missing(method)
52
+ end
53
+
54
+ hash
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,60 @@
1
+ require "openssl"
2
+
3
+ module GpWebpay
4
+ class Verification
5
+ def initialize(payment_attributes, verification_attrs = nil)
6
+ @payment_attributes = payment_attributes
7
+ @verification_attrs = verification_attrs
8
+ end
9
+
10
+ def verified_response?(params)
11
+ verify_digest(params["DIGEST"], digest_verification(params)) &&
12
+ verify_digest(params["DIGEST1"], digest1_verification(params))
13
+ end
14
+
15
+ def payment_attributes_with_digest
16
+ @payment_attributes.merge("DIGEST" => digest)
17
+ end
18
+
19
+ def digest
20
+ sign = merchant_key.sign(OpenSSL::Digest::SHA1.new, digest_text)
21
+ Base64.encode64(sign).gsub("\n", "")
22
+ end
23
+
24
+ private
25
+
26
+ def config
27
+ GpWebpay.config
28
+ end
29
+
30
+ def digest_text
31
+ @payment_attributes.values.join("|")
32
+ end
33
+
34
+ def digest_verification(params)
35
+ @verification_attrs.map { |key| params[key] }.join("|")
36
+ end
37
+
38
+ def digest1_verification(params)
39
+ digest_verification(params) + "|#{config.merchant_number}"
40
+ end
41
+
42
+ def verify_digest(signature, data)
43
+ gpe_key.verify(OpenSSL::Digest::SHA1.new, Base64.decode64(signature), data)
44
+ end
45
+
46
+ def merchant_key
47
+ @merchant_key ||= begin
48
+ pem = config.merchant_pem || File.read(config.merchant_pem_path)
49
+ OpenSSL::PKey::RSA.new(pem, config.merchant_password)
50
+ end
51
+ end
52
+
53
+ def gpe_key
54
+ @gpe_key ||= begin
55
+ pem = File.read config.gpe_pem_path
56
+ OpenSSL::X509::Certificate.new(pem).public_key
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,3 @@
1
+ module GpWebpay
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,125 @@
1
+ require "nokogiri"
2
+ require "curb"
3
+ require "active_support/core_ext/hash"
4
+ require "gp_webpay/web_services/template"
5
+ require "gp_webpay/web_services/response"
6
+
7
+ module GpWebpay
8
+ module WebServices
9
+ extend ActiveSupport::Concern
10
+
11
+ def send_request(request_xml)
12
+ request = Curl::Easy.new(config.web_services_url)
13
+ request.headers["Content-Type"] = "text/xml;charset=UTF-8"
14
+ request.http_post(request_xml)
15
+ request
16
+ end
17
+
18
+ ##
19
+ # Expected output
20
+ # <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
21
+ # <soapenv:Body>
22
+ # <ns2:echoResponse xmlns:ns2="http://gpe.cz/pay/pay-ws/core" xmlns="http://gpe.cz/pay/pay-ws/core/type"/>
23
+ # </soapenv:Body>
24
+ # </soapenv:Envelope>
25
+ ##
26
+ def ws_echo
27
+ get_params_from(send_request(template.echo).body_str)
28
+ end
29
+
30
+ def ws_process_regular_subscription_payment
31
+ attributes = request_attributes("processRegularSubscriptionPayment")
32
+ raw_response = send_request(template.process_regular_subscription_payment(attributes)).body_str
33
+ get_params_from(raw_response)
34
+ end
35
+
36
+ def ws_get_payment_detail
37
+ attributes = request_attributes("getPaymentDetail")
38
+ raw_response = send_request(template.get_payment_detail(attributes)).body_str
39
+ get_params_from(raw_response)
40
+ end
41
+
42
+ def ws_get_payment_status
43
+ attributes = request_attributes("getPaymentStatus")
44
+ raw_response = send_request(template.get_payment_status(attributes)).body_str
45
+ get_params_from(raw_response)
46
+ end
47
+
48
+ def ws_get_master_payment_status
49
+ attributes = request_attributes("getMasterPaymentStatus")
50
+ raw_response = send_request(template.get_master_payment_status(attributes)).body_str
51
+ get_params_from(raw_response)
52
+ end
53
+
54
+ def message_id(type = "")
55
+ "#{order_number}0100#{config.merchant_number}#{type}#{Time.now.to_i}"
56
+ end
57
+
58
+ def bank_id
59
+ "0100"
60
+ end
61
+
62
+ def capture_flag
63
+ 1
64
+ end
65
+
66
+ private
67
+
68
+ def get_params_from(response)
69
+ hash_response = Hash.from_xml(Nokogiri::XML(response).to_s)["Envelope"]["Body"]
70
+ first_lvl_key = hash_response.keys.first
71
+ hash_response = hash_response["#{first_lvl_key}"]
72
+ second_lvl_key = hash_response.keys.last
73
+ hash_response = hash_response["#{second_lvl_key}"]
74
+ GpWebpay::WebServices::Response.new(hash_response)
75
+ end
76
+
77
+ def request_attributes(type = "")
78
+ {
79
+ message_id: message_id(type),
80
+ merchant_number: config.merchant_number,
81
+ order_number: order_number,
82
+ merchant_order_number: merchant_order_number,
83
+ master_order_number: master_order_number,
84
+ amount: amount_in_cents,
85
+ capture_flag: capture_flag,
86
+ card_holder_name: card_holder.name,
87
+ card_holder_email: card_holder.email,
88
+ card_holder_phone_country: card_holder.phone_country,
89
+ card_holder_phone: card_holder.phone,
90
+ card_holder_mobile_phone_country: card_holder.mobile_phone_country,
91
+ card_holder_mobile_phone: card_holder.mobile_phone,
92
+ address_match: address_match,
93
+ billing_name: billing.name,
94
+ billing_address1: billing.address1,
95
+ billing_city: billing.city,
96
+ billing_postal_code: billing.postal_code,
97
+ billing_country: billing.country,
98
+ shipping_name: shipping.name,
99
+ shipping_address1: shipping.address1,
100
+ shipping_city: shipping.city,
101
+ shipping_postal_code: shipping.postal_code,
102
+ shipping_country: shipping.country,
103
+ digest: ws_verification(type).digest,
104
+ # Deprecated Attrs, will remove
105
+ currency: currency,
106
+ }
107
+ end
108
+
109
+ def config
110
+ GpWebpay.config
111
+ end
112
+
113
+ def template
114
+ GpWebpay::WebServices::Template.new
115
+ end
116
+
117
+ def ws_attributes(type)
118
+ PaymentAttributes.new(self, true, type).to_h
119
+ end
120
+
121
+ def ws_verification(type)
122
+ ::GpWebpay::Verification.new(ws_attributes(type))
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,18 @@
1
+ module GpWebpay
2
+ module WebServices
3
+ class Response
4
+ attr_accessor :plain
5
+
6
+ def initialize(data)
7
+ @plain = data
8
+
9
+ return unless data.respond_to?(:keys)
10
+ data.keys.each do |key|
11
+ define_singleton_method key.underscore do
12
+ data[key]
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,225 @@
1
+ module GpWebpay
2
+ module WebServices
3
+ class Template
4
+
5
+ ##
6
+ # Generated XML request body
7
+ # <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:core="http://gpe.cz/pay/pay-ws/core">
8
+ # <soapenv:Header/>
9
+ # <soapenv:Body>
10
+ # <v1:echo/>
11
+ # </soapenv:Body>
12
+ # </soapenv:Envelope>
13
+ ##
14
+ def echo
15
+ ::Nokogiri::XML::Builder.new(:encoding => "utf-8") do |xml|
16
+ xml.send("soapenv:Envelope", "xmlns:soapenv" => "http://schemas.xmlsoap.org/soap/envelope/", "xmlns:v1" => "http://gpe.cz/pay/pay-ws/proc/v1") {
17
+ xml.send("soapenv:Header")
18
+ xml.send("soapenv:Body") {
19
+ xml.send("v1:echo")
20
+ }
21
+ }
22
+ end.to_xml
23
+ end
24
+
25
+ ##
26
+ # <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://gpe.cz/pay/pay-ws/proc/v1" xmlns:type="http://gpe.cz/pay/pay-ws/proc/v1/type">
27
+ # <soapenv:Header/>
28
+ # <soapenv:Body>
29
+ # <v1:processRegularSubscriptionPayment>
30
+ # <v1:regularSubscriptionPaymentRequest>
31
+ # <type:messageId>?</type:messageId>
32
+ # <type:provider>?</type:provider> -> previously as acquirer
33
+ # <type:merchantNumber>?</type:merchantNumber>
34
+ # <type:paymentNumber>?</type:paymentNumber> -> previously orderNumber (now optional)
35
+ # <type:masterPaymentNumber>?</type:masterPaymentNumber>
36
+ # <type:orderNumber>?</type:orderNumber>
37
+ # <type:subscriptionAmount>?</type:subscriptionAmount> -> previously amount, now unable to change
38
+ # <type:captureFlag>?</type:captureFlag>
39
+ # <type:cardHolderData>
40
+ # <type:cardholderDetails>
41
+ # <type:name>?</type:name>
42
+ # <type:email>?</type:email>
43
+ # <type:phoneCountry>?</type:phoneCountry>
44
+ # <type:phone>?</type:phone>
45
+ # <type:mobilePhoneCountry>?</type:mobilePhoneCountry>
46
+ # <type:mobilePhone>?</type:mobilePhone>
47
+ # <type:clientIpAddress>?</type:clientIpAddress>
48
+ # </type:cardholderDetails>
49
+ # <type:addressMatch>?</type:addressMatch>
50
+ # <type:billingDetails>
51
+ # <type:name>?</type:name>
52
+ # <type:address1>?</type:address1>
53
+ # <type:city>?</type:city>
54
+ # <type:postalCode>?</type:postalCode>
55
+ # <type:country>?</type:country>
56
+ # </type:billingDetails>
57
+ # <type:shippingDetails>
58
+ # <type:name>?</type:name>
59
+ # <type:address1>?</type:address1>
60
+ # <type:city>?</type:city>
61
+ # <type:postalCode>?</type:postalCode>
62
+ # <type:country>?</type:country>
63
+ # </type:shippingDetails>
64
+ # </type:cardHolderData>
65
+ # <type:signature>cid:992953179904</type:signature>
66
+ # </v1:regularSubscriptionPaymentRequest>
67
+ # </v1:processRegularSubscriptionPayment>
68
+ # </soapenv:Body>
69
+ # </soapenv:Envelope>
70
+ ##
71
+ def process_regular_subscription_payment(attributes = {})
72
+ ::Nokogiri::XML::Builder.new(:encoding => "utf-8") do |xml|
73
+ xml.send("soapenv:Envelope", "xmlns:soapenv" => "http://schemas.xmlsoap.org/soap/envelope/", "xmlns:v1" => "http://gpe.cz/pay/pay-ws/proc/v1", "xmlns:type" => "http://gpe.cz/pay/pay-ws/proc/v1/type") {
74
+ xml.send("soapenv:Header")
75
+ xml.send("soapenv:Body") {
76
+ xml.send("v1:processRegularSubscriptionPayment") {
77
+ xml.send("v1:regularSubscriptionPaymentRequest") {
78
+ xml.send("type:messageId", attributes[:message_id])
79
+ xml.send("type:provider", "0100")
80
+ xml.send("type:merchantNumber", attributes[:merchant_number])
81
+ xml.send("type:paymentNumber", attributes[:order_number])
82
+ xml.send("type:masterPaymentNumber", attributes[:master_order_number])
83
+ xml.send("type:orderNumber", attributes[:merchant_order_number])
84
+ xml.send("type:subscriptionAmount", attributes[:amount])
85
+ xml.send("type:captureFlag", attributes[:capture_flag])
86
+ xml.send("type:cardHolderData") {
87
+ xml.send("type:cardholderDetails") {
88
+ xml.send("type:name", attributes[:card_holder_name])
89
+ xml.send("type:email", attributes[:card_holder_email])
90
+ xml.send("type:phoneCountry", attributes[:card_holder_phone_country])
91
+ xml.send("type:phone", attributes[:card_holder_phone])
92
+ xml.send("type:mobilePhoneCountry", attributes[:card_holder_mobile_phone_country])
93
+ xml.send("type:mobilePhone", attributes[:card_holder_mobile_phone])
94
+ }
95
+ xml.send("type:addressMatch", attributes[:address_match])
96
+ xml.send("type:billingDetails") {
97
+ xml.send("type:name", attributes[:billing_name])
98
+ xml.send("type:address1", attributes[:billing_address1])
99
+ xml.send("type:city", attributes[:billing_city])
100
+ xml.send("type:postalCode", attributes[:billing_postal_code])
101
+ xml.send("type:country", attributes[:billing_country])
102
+ }
103
+ xml.send("type:shippingDetails") {
104
+ xml.send("type:name", attributes[:shipping_name])
105
+ xml.send("type:address1", attributes[:shipping_address1])
106
+ xml.send("type:city", attributes[:shipping_city])
107
+ xml.send("type:postalCode", attributes[:shipping_postal_code])
108
+ xml.send("type:country", attributes[:shipping_country])
109
+ }
110
+ }
111
+ xml.send("type:signature", attributes[:digest])
112
+ }
113
+ }
114
+ }
115
+ }
116
+ end.to_xml
117
+ end
118
+
119
+ ##
120
+ # <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://gpe.cz/pay/pay-ws/proc/v1" xmlns:type="http://gpe.cz/pay/pay-ws/proc/v1/type">
121
+ # <soapenv:Header/>
122
+ # <soapenv:Body>
123
+ # <v1:getPaymentDetail>
124
+ # <v1:paymentDetailRequest>
125
+ # <type:messageId>?</type:messageId>
126
+ # <type:provider>?</type:provider>
127
+ # <type:merchantNumber>?</type:merchantNumber>
128
+ # <type:paymentNumber>?</type:paymentNumber>
129
+ # <type:signature>cid:1203306453242</type:signature>
130
+ # </v1:paymentDetailRequest>
131
+ # </v1:getPaymentDetail>
132
+ # </soapenv:Body>
133
+ # </soapenv:Envelope>
134
+ ##
135
+ def get_payment_detail(attributes = {})
136
+ ::Nokogiri::XML::Builder.new(:encoding => "utf-8") do |xml|
137
+ xml.send("soapenv:Envelope", "xmlns:soapenv" => "http://schemas.xmlsoap.org/soap/envelope/", "xmlns:v1" => "http://gpe.cz/pay/pay-ws/proc/v1", "xmlns:type" => "http://gpe.cz/pay/pay-ws/proc/v1/type") {
138
+ xml.send("soapenv:Header")
139
+ xml.send("soapenv:Body") {
140
+ xml.send("v1:getPaymentDetail") {
141
+ xml.send("v1:paymentDetailRequest") {
142
+ xml.send("type:messageId", attributes[:message_id])
143
+ xml.send("type:provider", "0100")
144
+ xml.send("type:merchantNumber", attributes[:merchant_number])
145
+ xml.send("type:paymentNumber", attributes[:order_number])
146
+ xml.send("type:signature", attributes[:digest])
147
+ }
148
+ }
149
+ }
150
+ }
151
+ end.to_xml
152
+ end
153
+
154
+ ##
155
+ # <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://gpe.cz/pay/pay-ws/proc/v1" xmlns:type="http://gpe.cz/pay/pay-ws/proc/v1/type">
156
+ # <soapenv:Header/>
157
+ # <soapenv:Body>
158
+ # <v1:getPaymentStatus>
159
+ # <v1:paymentStatusRequest>
160
+ # <type:messageId>?</type:messageId>
161
+ # <type:provider>?</type:provider>
162
+ # <type:merchantNumber>?</type:merchantNumber>
163
+ # <type:paymentNumber>?</type:paymentNumber>
164
+ # <type:signature>cid:619237523074</type:signature>
165
+ # </v1:paymentStatusRequest>
166
+ # </v1:getPaymentStatus>
167
+ # </soapenv:Body>
168
+ # </soapenv:Envelope>
169
+ ##
170
+ def get_payment_status(attributes = {})
171
+ ::Nokogiri::XML::Builder.new(:encoding => "utf-8") do |xml|
172
+ xml.send("soapenv:Envelope", "xmlns:soapenv" => "http://schemas.xmlsoap.org/soap/envelope/", "xmlns:v1" => "http://gpe.cz/pay/pay-ws/proc/v1", "xmlns:type" => "http://gpe.cz/pay/pay-ws/proc/v1/type") {
173
+ xml.send("soapenv:Header")
174
+ xml.send("soapenv:Body") {
175
+ xml.send("v1:getPaymentStatus") {
176
+ xml.send("v1:paymentStatusRequest") {
177
+ xml.send("type:messageId", attributes[:message_id])
178
+ xml.send("type:provider", "0100")
179
+ xml.send("type:merchantNumber", attributes[:merchant_number])
180
+ xml.send("type:paymentNumber", attributes[:order_number])
181
+ xml.send("type:signature", attributes[:digest])
182
+ }
183
+ }
184
+ }
185
+ }
186
+ end.to_xml
187
+ end
188
+
189
+ ##
190
+ # <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://gpe.cz/pay/pay-ws/proc/v1" xmlns:type="http://gpe.cz/pay/pay-ws/proc/v1/type">
191
+ # <soapenv:Header/>
192
+ # <soapenv:Body>
193
+ # <v1:getMasterPaymentStatus>
194
+ # <v1:masterPaymentStatusRequest>
195
+ # <type:messageId>?</type:messageId>
196
+ # <type:provider>?</type:provider>
197
+ # <type:merchantNumber>?</type:merchantNumber>
198
+ # <type:paymentNumber>?</type:paymentNumber>
199
+ # <type:signature>cid:300161986033</type:signature>
200
+ # </v1:masterPaymentStatusRequest>
201
+ # </v1:getMasterPaymentStatus>
202
+ # </soapenv:Body>
203
+ # </soapenv:Envelope>
204
+ ##
205
+ def get_master_payment_status(attributes = {})
206
+ ::Nokogiri::XML::Builder.new(:encoding => "utf-8") do |xml|
207
+ xml.send("soapenv:Envelope", "xmlns:soapenv" => "http://schemas.xmlsoap.org/soap/envelope/", "xmlns:v1" => "http://gpe.cz/pay/pay-ws/proc/v1", "xmlns:type" => "http://gpe.cz/pay/pay-ws/proc/v1/type") {
208
+ xml.send("soapenv:Header")
209
+ xml.send("soapenv:Body") {
210
+ xml.send("v1:getMasterPaymentStatus") {
211
+ xml.send("v1:masterPaymentStatusRequest") {
212
+ xml.send("type:messageId", attributes[:message_id])
213
+ xml.send("type:provider", "0100")
214
+ xml.send("type:merchantNumber", attributes[:merchant_number])
215
+ xml.send("type:paymentNumber", attributes[:order_number])
216
+ xml.send("type:signature", attributes[:digest])
217
+ }
218
+ }
219
+ }
220
+ }
221
+ end.to_xml
222
+ end
223
+ end
224
+ end
225
+ end
metadata ADDED
@@ -0,0 +1,246 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-gpwebpay
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Andrej Antas
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-03-02 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: nokogiri
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: curb
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.14'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.14'
111
+ - !ruby/object:Gem::Dependency
112
+ name: vcr
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: webmock
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '3.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '3.0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: pry
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: wasabi
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: libxml-ruby
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: timecop
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ description:
196
+ email:
197
+ - andrej@antas.cz
198
+ executables: []
199
+ extensions: []
200
+ extra_rdoc_files: []
201
+ files:
202
+ - ".gitignore"
203
+ - ".rspec"
204
+ - ".ruby_gemset"
205
+ - ".travis.yml"
206
+ - Gemfile
207
+ - README.md
208
+ - Rakefile
209
+ - bin/console
210
+ - bin/setup
211
+ - certs/muzo.signing_prod.pem
212
+ - certs/muzo.signing_test.pem
213
+ - gp_webpay.gemspec
214
+ - lib/gp_webpay.rb
215
+ - lib/gp_webpay/config.rb
216
+ - lib/gp_webpay/payment.rb
217
+ - lib/gp_webpay/payment_attributes.rb
218
+ - lib/gp_webpay/verification.rb
219
+ - lib/gp_webpay/version.rb
220
+ - lib/gp_webpay/web_services.rb
221
+ - lib/gp_webpay/web_services/response.rb
222
+ - lib/gp_webpay/web_services/template.rb
223
+ homepage: https://github.com/redrick/gpwebpay
224
+ licenses:
225
+ - MIT
226
+ metadata: {}
227
+ post_install_message:
228
+ rdoc_options: []
229
+ require_paths:
230
+ - lib
231
+ required_ruby_version: !ruby/object:Gem::Requirement
232
+ requirements:
233
+ - - ">="
234
+ - !ruby/object:Gem::Version
235
+ version: '0'
236
+ required_rubygems_version: !ruby/object:Gem::Requirement
237
+ requirements:
238
+ - - ">="
239
+ - !ruby/object:Gem::Version
240
+ version: '0'
241
+ requirements: []
242
+ rubygems_version: 3.0.8
243
+ signing_key:
244
+ specification_version: 4
245
+ summary: GP webpay, payments, SOAP, payment gateway
246
+ test_files: []