payu-latam 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a84be94d4f0a0ba2f599d3ba610050d027a1f26a1112c55d742ea991071ae56b
4
+ data.tar.gz: 6da4fa2d6a81dc63584e7f9c9fa284db28cb6696354def9b5f729799f25babf9
5
+ SHA512:
6
+ metadata.gz: 9204b3df388918a26f598c8b2c39cfd04b34e014f3a5d70a91da20c1167c8f8b150264d5f6e61b73485f0a6bfe428c97847df1e4b63e105e89c6afe9802c4c5c
7
+ data.tar.gz: dc87609dd016f1550ca3f9ecc2a3fa974c7763ec4a7fcf811c18e2680d67211e78aad6be976462b5ada9483030deb4f863d46b058856895a0c7dba4585848c51
@@ -0,0 +1,53 @@
1
+ # Ruby CircleCI 2.0 configuration file
2
+ #
3
+ # Check https://circleci.com/docs/2.0/language-ruby/ for more details
4
+ #
5
+ version: 2
6
+ jobs:
7
+ build:
8
+ docker:
9
+ # specify the version you desire here
10
+ - image: circleci/ruby:2.4.1-node-browsers
11
+
12
+ # Specify service dependencies here if necessary
13
+ # CircleCI maintains a library of pre-built images
14
+ # documented at https://circleci.com/docs/2.0/circleci-images/
15
+ # - image: circleci/postgres:9.4
16
+
17
+ working_directory: ~/repo
18
+
19
+ steps:
20
+ - checkout
21
+
22
+ # Download and cache dependencies
23
+ - restore_cache:
24
+ keys:
25
+ - v1-dependencies-{{ checksum "Gemfile.lock" }}
26
+ # fallback to using the latest cache if no exact match is found
27
+ - v1-dependencies-
28
+
29
+ - run:
30
+ name: install dependencies
31
+ command: |
32
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
33
+
34
+ - save_cache:
35
+ paths:
36
+ - ./vendor/bundle
37
+ key: v1-dependencies-{{ checksum "Gemfile.lock" }}
38
+
39
+ # run tests!
40
+ - run:
41
+ name: run tests
42
+ command: |
43
+ mkdir /tmp/test-results
44
+ TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
45
+
46
+ bundle exec rspec --format progress --format RspecJunitFormatter --out /tmp/test-results/rspec.xml $TEST_FILES
47
+
48
+ # collect reports
49
+ - store_test_results:
50
+ path: /tmp/test-results
51
+ - store_artifacts:
52
+ path: /tmp/test-results
53
+ destination: test-results
@@ -0,0 +1,8 @@
1
+ /payu-latam-*.gem
2
+ /Gemfile.lock
3
+ .rvmrc
4
+ Gemfile.lock
5
+ tags
6
+ /.bundle/
7
+ coverage/
8
+ .rspec_status
@@ -0,0 +1,99 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.1
3
+
4
+ Naming/PredicateName:
5
+ Enabled: false
6
+
7
+ Layout/IndentHash:
8
+ EnforcedStyle: consistent
9
+
10
+ Layout/AlignHash:
11
+ EnforcedLastArgumentHashStyle: ignore_implicit
12
+
13
+ Style/Documentation:
14
+ Enabled: false
15
+
16
+ Style/FrozenStringLiteralComment:
17
+ Enabled: false
18
+
19
+ Layout/IndentArray:
20
+ EnforcedStyle: consistent
21
+
22
+ Style/SymbolArray:
23
+ EnforcedStyle: brackets
24
+
25
+ Style/WordArray:
26
+ EnforcedStyle: brackets
27
+
28
+ Style/ClassAndModuleChildren:
29
+ EnforcedStyle: compact
30
+
31
+ Layout/SpaceInsideHashLiteralBraces:
32
+ Enabled: true
33
+ EnforcedStyle: no_space
34
+
35
+ Style/IfUnlessModifier:
36
+ Enabled: false
37
+
38
+ Style/StringLiterals:
39
+ EnforcedStyle: double_quotes
40
+
41
+ Style/Lambda:
42
+ Enabled: false
43
+
44
+ Layout/MultilineOperationIndentation:
45
+ EnforcedStyle: indented
46
+
47
+ Layout/MultilineMethodCallIndentation:
48
+ EnforcedStyle: indented
49
+
50
+ Layout/AlignParameters:
51
+ EnforcedStyle: with_fixed_indentation
52
+
53
+ Layout/EmptyLineBetweenDefs:
54
+ NumberOfEmptyLines: 2
55
+
56
+ Layout/EmptyLines:
57
+ Enabled: false
58
+
59
+ Style/TrailingCommaInArrayLiteral:
60
+ EnforcedStyleForMultiline: comma
61
+
62
+ Style/TrailingCommaInHashLiteral:
63
+ EnforcedStyleForMultiline: comma
64
+
65
+ Style/TrailingCommaInArguments:
66
+ EnforcedStyleForMultiline: comma
67
+
68
+ Style/ClassAndModuleChildren:
69
+ EnforcedStyle: compact
70
+
71
+ Metrics/ParameterLists:
72
+ Max: 5
73
+
74
+ Metrics/BlockLength:
75
+ Max: 50
76
+
77
+ Metrics/MethodLength:
78
+ Max: 50
79
+
80
+ Metrics/ClassLength:
81
+ Max: 200
82
+
83
+ Metrics/ModuleLength:
84
+ Max: 200
85
+
86
+ Metrics/CyclomaticComplexity:
87
+ Max: 30
88
+
89
+ Metrics/PerceivedComplexity:
90
+ Max: 30
91
+
92
+ Metrics/AbcSize:
93
+ Max: 30
94
+
95
+ Metrics/LineLength:
96
+ Max: 100
97
+
98
+ Style/AccessModifierDeclarations:
99
+ EnforcedStyle: inline
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Lengio Corporation
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 all
13
+ 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 THE
21
+ SOFTWARE.
@@ -0,0 +1,40 @@
1
+ # PayU Latam Ruby Library
2
+
3
+ [![CircleCI](https://circleci.com/gh/lengio/payu-latam-ruby.svg?style=svg)](https://circleci.com/gh/lengio/payu-latam-ruby)
4
+ [![Coverage Status](https://coveralls.io/repos/github/lengio/payu-latam-ruby/badge.svg?branch=master)](https://coveralls.io/github/lengio/payu-latam-ruby?branch=master)
5
+ [![Maintainability](https://api.codeclimate.com/v1/badges/28162c8ec3dfe0ec4227/maintainability)](https://codeclimate.com/github/lengio/payu-latam-ruby/maintainability)
6
+
7
+ ## Installation
8
+
9
+ gem "payu-latam", github: "lengio/payu-latam-ruby", require: "pay_u"
10
+
11
+ # Local
12
+ gem build payu-latam.gemspec
13
+
14
+ ## Usage
15
+
16
+ ```ruby
17
+ require "pay_u"
18
+
19
+ PayU.configure do |config|
20
+ config.api_key = "4Vj8eK4rloUd272L48hsrarnUA" # Replace with your own API key
21
+ config.merchant_id = 508029 # Replace with your own merchant ID
22
+ config.test = true # Test mode
23
+ end
24
+
25
+ order = PayU::Order.new(
26
+ amount: 20_000,
27
+ currency: :COP,
28
+ description: "Test PAYU"
29
+ )
30
+
31
+ order.form.params
32
+ ```
33
+
34
+ ## Testing
35
+
36
+ rspec
37
+
38
+ ## Console
39
+
40
+ bin/console
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "pay_u"
5
+
6
+ require "pry"
7
+ Pry.start
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
@@ -0,0 +1,15 @@
1
+ require "bigdecimal"
2
+ require "virtus"
3
+
4
+ require "pay_u/version"
5
+
6
+ require "pay_u/constants"
7
+ require "pay_u/configuration"
8
+ require "pay_u/signer/base"
9
+ require "pay_u/signer/form"
10
+ require "pay_u/signer/response"
11
+ require "pay_u/signer/confirmation"
12
+ require "pay_u/order"
13
+ require "pay_u/form"
14
+ require "pay_u/response"
15
+ require "pay_u/confirmation"
@@ -0,0 +1,53 @@
1
+ module PayU
2
+ class Configuration
3
+ include Virtus.model
4
+
5
+ attribute :api_key, String
6
+ attribute :merchant_id, String
7
+ attribute :account_ids, Hash
8
+ attribute :test, Boolean
9
+ attribute :response_url, String
10
+ attribute :confirmation_url, String
11
+
12
+ def initialize(params = {})
13
+ super(params)
14
+
15
+ self.api_key = ENV.fetch("PAYU_API_KEY", "4Vj8eK4rloUd272L48hsrarnUA") if api_key.nil?
16
+ self.merchant_id = ENV.fetch("PAYU_MERCHANT_ID", 508_029) if merchant_id.nil?
17
+ self.test = ENV.fetch("PAYU_TEST", true) if test.nil?
18
+ self.account_ids = {
19
+ AR: 512_322,
20
+ BR: 512_327,
21
+ CL: 512_325,
22
+ CO: 512_321,
23
+ MX: 512_324,
24
+ PA: 512_326,
25
+ PE: 512_323,
26
+ }
27
+ end
28
+
29
+
30
+ def test?
31
+ test
32
+ end
33
+ end
34
+
35
+ def self.configuration
36
+ @configuration ||= Configuration.new
37
+ end
38
+
39
+
40
+ def self.configuration=(configuration)
41
+ @configuration = configuration
42
+ end
43
+
44
+
45
+ def self.configure
46
+ yield configuration
47
+ end
48
+
49
+
50
+ def self.reset
51
+ @configuration = Configuration.new
52
+ end
53
+ end
@@ -0,0 +1,28 @@
1
+ class PayU::Confirmation
2
+ include Virtus.model
3
+
4
+ attribute :order, PayU::Order
5
+ attribute :signature, String
6
+
7
+ attr_reader :signer
8
+
9
+ def initialize(params)
10
+ @signature = params[:sign]
11
+ @order = PayU::Order.new(
12
+ reference_code: params[:reference_sale],
13
+ amount: params[:value].to_f,
14
+ currency: params[:currency],
15
+ status_code: params[:state_pol].to_i,
16
+ response_code: params[:response_code_pol].to_i,
17
+ payment_method_code: params[:payment_method_type].to_i,
18
+ email: params[:email_buyer],
19
+ transaction_id: params[:transaction_id],
20
+ )
21
+ @signer = PayU::Signer::Confirmation.new(@order.attributes)
22
+ end
23
+
24
+
25
+ def valid?
26
+ signature == signer.signature
27
+ end
28
+ end
@@ -0,0 +1,4 @@
1
+ module PayU
2
+ TEST_URL = "https://sandbox.checkout.payulatam.com/ppp-web-gateway-payu/".freeze
3
+ LIVE_URL = "https://checkout.payulatam.com/ppp-web-gateway-payu/".freeze
4
+ end
@@ -0,0 +1,38 @@
1
+ class PayU::Form
2
+ include Virtus.model
3
+
4
+ attribute :order, PayU::Order
5
+
6
+ attr_reader :signer
7
+
8
+ def initialize(params)
9
+ super(params)
10
+ @signer = PayU::Signer::Form.new(order.attributes)
11
+ end
12
+
13
+
14
+ def signature
15
+ signer.signature
16
+ end
17
+
18
+
19
+ def params
20
+ {
21
+ action: order.test? ? PayU::TEST_URL : PayU::LIVE_URL,
22
+ fields: {
23
+ merchantId: order.merchant_id,
24
+ accountId: order.account_id,
25
+ description: order.description,
26
+ referenceCode: order.reference_code,
27
+ amount: order.amount,
28
+ tax: order.tax,
29
+ taxReturnBase: order.tax_return_base,
30
+ currency: order.currency,
31
+ signature: signature,
32
+ test: order.test? ? "1" : "0",
33
+ responseUrl: order.response_url,
34
+ confirmationUrl: order.confirmation_url,
35
+ },
36
+ }
37
+ end
38
+ end
@@ -0,0 +1,56 @@
1
+ class PayU::Order
2
+ include Virtus.model
3
+
4
+ APPROVED = 4
5
+ DECLINED = 6
6
+ ERROR = 104
7
+ EXPIRED = 5
8
+ PENDING = 7
9
+
10
+ attribute :account_id, Integer
11
+ attribute :reference_code, String
12
+ attribute :amount, BigDecimal
13
+ attribute :currency, Symbol
14
+ attribute :description, String
15
+ attribute :tax, BigDecimal
16
+ attribute :tax_return_base, BigDecimal
17
+ attribute :status_code, Integer
18
+ attribute :response_code, Integer
19
+ attribute :payment_method_code, Integer
20
+ attribute :email, String
21
+ attribute :transaction_id, String
22
+
23
+ def initialize(params)
24
+ super(params)
25
+ end
26
+
27
+
28
+ def merchant_id
29
+ PayU.configuration.merchant_id
30
+ end
31
+
32
+
33
+ def test?
34
+ PayU.configuration.test?
35
+ end
36
+
37
+
38
+ def response_url
39
+ PayU.configuration.response_url
40
+ end
41
+
42
+
43
+ def confirmation_url
44
+ PayU.configuration.confirmation_url
45
+ end
46
+
47
+
48
+ def form
49
+ @form ||= PayU::Form.new(order: self)
50
+ end
51
+
52
+
53
+ def attributes
54
+ super.merge(merchant_id: merchant_id)
55
+ end
56
+ end
@@ -0,0 +1,28 @@
1
+ class PayU::Response
2
+ include Virtus.model
3
+
4
+ attribute :order, PayU::Order
5
+ attribute :signature, String
6
+
7
+ attr_reader :signer
8
+
9
+ def initialize(params)
10
+ @signature = params[:signature]
11
+ @order = PayU::Order.new(
12
+ reference_code: params[:referenceCode],
13
+ amount: params[:TX_VALUE].to_f,
14
+ currency: params[:currency],
15
+ status_code: params[:transactionState].to_i,
16
+ response_code: params[:polResponseCode].to_i,
17
+ payment_method_code: params[:polPaymentMethodType].to_i,
18
+ email: params[:buyerEmail],
19
+ transaction_id: params[:transactionId],
20
+ )
21
+ @signer = PayU::Signer::Response.new(@order.attributes)
22
+ end
23
+
24
+
25
+ def valid?
26
+ signature == signer.signature
27
+ end
28
+ end
@@ -0,0 +1,24 @@
1
+ require "digest"
2
+
3
+ module PayU::Signer
4
+ class Base
5
+ SIGNATURE_JOIN = "~".freeze
6
+
7
+ include Virtus.model
8
+
9
+ attribute :merchant_id, Integer
10
+ attribute :reference_code, String
11
+ attribute :amount, BigDecimal
12
+ attribute :currency, Symbol
13
+ attribute :status_code, Integer
14
+
15
+ def signature
16
+ Digest::MD5.hexdigest(fields.join(SIGNATURE_JOIN))
17
+ end
18
+
19
+
20
+ private def api_key
21
+ PayU.configuration.api_key
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,16 @@
1
+ module PayU::Signer
2
+ class Confirmation < PayU::Signer::Base
3
+ def fields
4
+ value = format("%.2f", amount)
5
+
6
+ [
7
+ api_key,
8
+ merchant_id,
9
+ reference_code,
10
+ value[-1] == "0" ? value[0..-2] : value,
11
+ currency,
12
+ status_code,
13
+ ]
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ module PayU::Signer
2
+ class Form < PayU::Signer::Base
3
+ def fields
4
+ [
5
+ api_key,
6
+ merchant_id,
7
+ reference_code,
8
+ format("%<amount>g", amount: format("%<amount>f", amount: amount)),
9
+ currency,
10
+ ]
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ module PayU::Signer
2
+ class Response < PayU::Signer::Base
3
+ def fields
4
+ [
5
+ api_key,
6
+ merchant_id,
7
+ reference_code,
8
+ format("%.1f", amount),
9
+ currency,
10
+ status_code,
11
+ ]
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module PayU
2
+ VERSION = "1.0.0".freeze
3
+ end
@@ -0,0 +1,33 @@
1
+ $LOAD_PATH.unshift(::File.join(::File.dirname(__FILE__), "lib"))
2
+
3
+ require "pay_u/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "payu-latam"
7
+ spec.version = PayU::VERSION
8
+ spec.required_ruby_version = ">= 2.1.0"
9
+ spec.summary = "Ruby bindings for the PayU Latam API"
10
+ spec.description = "Accept payments with PayU Latam: http://developerspec.payulatam.com/es/."
11
+ spec.author = "Slang"
12
+ spec.email = "engineering@slang.com"
13
+ spec.homepage = "https://slangapp.com"
14
+ spec.license = "MIT"
15
+
16
+ spec.add_dependency "virtus", "~> 1.0"
17
+
18
+ spec.add_development_dependency "bundler", "~> 1.15"
19
+ spec.add_development_dependency "byebug", "~> 10.0"
20
+ spec.add_development_dependency "coveralls", "~> 0"
21
+ spec.add_development_dependency "pry", "~> 0.12"
22
+ spec.add_development_dependency "pry-byebug", "~> 3.6"
23
+ spec.add_development_dependency "rspec", "~> 3.7"
24
+ spec.add_development_dependency "rspec_junit_formatter", "~> 0"
25
+ spec.add_development_dependency "rubocop", "~> 0.57"
26
+ spec.add_development_dependency "simplecov", "~> 0"
27
+ spec.add_development_dependency "webmock", "~> 1.9"
28
+
29
+ spec.files = `git ls-files`.split("\n")
30
+ spec.test_files = `git ls-files -- spec/*`.split("\n")
31
+ spec.executables = `git ls-files -- bin/*`.split("\n").map { |f| ::File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+ end
@@ -0,0 +1,68 @@
1
+ module Fixtures
2
+ def self.confirmation
3
+ {
4
+ value: "3.00",
5
+ customer_number: "",
6
+ description: "Test PAYU",
7
+ payment_method_type: "2",
8
+ billing_city: "",
9
+ antifraudMerchantId: "",
10
+ currency: "USD",
11
+ additional_value: "0.00",
12
+ state_pol: "4",
13
+ error_code_bank: "81",
14
+ administrative_fee_tax: "0.00",
15
+ shipping_address: "",
16
+ response_code_pol: "1",
17
+ email_buyer: "test@test.com",
18
+ office_phone: "",
19
+ cc_holder: "Approved",
20
+ transaction_date: "2018-12-27 15:38:01",
21
+ pse_bank: "",
22
+ extra2: "",
23
+ shipping_city: "",
24
+ billing_address: "",
25
+ billing_country: "CO",
26
+ payment_request_state: "A",
27
+ date: "2018.12.27 03:38:01",
28
+ transaction_bank_id: "608150",
29
+ extra1: "",
30
+ phone: "",
31
+ shipping_country: "CO",
32
+ cc_number: "************0086",
33
+ bank_referenced_name: "",
34
+ franchise: "VISA",
35
+ administrative_fee_base: "0.00",
36
+ cus: "CRED - 666934642",
37
+ bank_id: "10",
38
+ risk: "0.61",
39
+ commision_pol: "0.00",
40
+ transaction_id: "957aa79c-135d-413e-b7fc-83a75c8d5c4f",
41
+ payment_method_name: "VISA",
42
+ test: "0",
43
+ reference_sale: "2205229",
44
+ reference_pol: "845122533",
45
+ error_message_bank: "",
46
+ extra3: "",
47
+ pse_reference1: "",
48
+ pse_reference2: "",
49
+ pse_reference3: "",
50
+ sign: "cc3c8101113b056bc4b5b3d289dbb106",
51
+ tax: "0.00",
52
+ commision_pol_currency: "",
53
+ payment_method: "10",
54
+ installments_number: "1",
55
+ ip: "172.18.49.47",
56
+ nickname_buyer: "",
57
+ merchant_id: "508029",
58
+ administrative_fee: "0.00",
59
+ payment_method_id: "2",
60
+ response_message_pol: "APPROVED",
61
+ authorization_code: "608150",
62
+ airline_code: "",
63
+ nickname_seller: "",
64
+ attempts: "1",
65
+ exchange_rate: "2874.01",
66
+ }
67
+ end
68
+ end
@@ -0,0 +1,46 @@
1
+ module Fixtures
2
+ def self.response
3
+ {
4
+ merchantId: "508029",
5
+ transactionState: "4",
6
+ risk: "",
7
+ polResponseCode: "1",
8
+ referenceCode: "2205229",
9
+ reference_pol: "845122533",
10
+ signature: "cc3c8101113b056bc4b5b3d289dbb106",
11
+ polPaymentMethod: "10",
12
+ polPaymentMethodType: "2",
13
+ installmentsNumber: "1",
14
+ TX_VALUE: "3.00",
15
+ TX_TAX: ".00",
16
+ buyerEmail: "test@test.com",
17
+ processingDate: "2018-12-27",
18
+ currency: "USD",
19
+ cus: "CRED - 666934642",
20
+ pseBank: "",
21
+ pseCycle: "",
22
+ pseReference1: "",
23
+ pseReference2: "",
24
+ pseReference3: "",
25
+ lng: "es",
26
+ description: "Test PAYU",
27
+ lapResponseCode: "APPROVED",
28
+ lapPaymentMethod: "VISA",
29
+ lapPaymentMethodType: "CREDIT_CARD",
30
+ lapTransactionState: "APPROVED",
31
+ message: "APPROVED",
32
+ extra1: "",
33
+ extra2: "",
34
+ extra3: "",
35
+ authorizationCode: "608150",
36
+ merchant_address: "Av 123 Calle 12",
37
+ merchant_name: "Test PayU Test comercio",
38
+ merchant_url: "http://pruebaslapv.xtrweb.com",
39
+ orderLanguage: "es",
40
+ telephone: "7512354",
41
+ transactionId: "957aa79c-135d-413e-b7fc-83a75c8d5c4f",
42
+ trazabilityCode: "CRED - 666934642",
43
+ polTransactionState: "4",
44
+ }
45
+ end
46
+ end
@@ -0,0 +1,33 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe PayU::Configuration do
4
+ let(:default_api_key) { "4Vj8eK4rloUd272L48hsrarnUA" }
5
+
6
+ it "assigns defaults" do
7
+ expect(PayU.configuration.api_key).to eq(default_api_key)
8
+ expect(PayU.configuration.test).to be_truthy
9
+ end
10
+
11
+ it "configures PayU with block" do
12
+ api_key = "12345"
13
+ PayU.configure do |config|
14
+ config.api_key = api_key
15
+ config.test = false
16
+ end
17
+
18
+ expect(PayU.configuration.api_key).to eq(api_key)
19
+ expect(PayU.configuration.test).to be_falsy
20
+ end
21
+
22
+ it "resets config" do
23
+ PayU.reset
24
+
25
+ expect(PayU.configuration.api_key).to eq(default_api_key)
26
+ end
27
+
28
+ it "assigns config" do
29
+ PayU.configuration = PayU::Configuration.new(test: false)
30
+
31
+ expect(PayU.configuration.test).to be_falsy
32
+ end
33
+ end
@@ -0,0 +1,42 @@
1
+ require "spec_helper"
2
+ require "fixtures/confirmation"
3
+
4
+ RSpec.describe PayU::Confirmation do
5
+ it "creates object from callback" do
6
+ confirmation = PayU::Confirmation.new(Fixtures.confirmation)
7
+
8
+ expect(confirmation.order.reference_code).to eq(Fixtures.confirmation[:reference_sale])
9
+ expect(confirmation.order.transaction_id).to eq(Fixtures.confirmation[:transaction_id])
10
+ expect(confirmation.valid?).to be_truthy
11
+ end
12
+
13
+ # Example from http://developers.payulatam.com/es/web_checkout/integration.html
14
+ it "validates signature" do
15
+ confirmation = PayU::Confirmation.new(params.merge(
16
+ reference_sale: "TestPayU04",
17
+ value: "150.00",
18
+ state_pol: PayU::Order::DECLINED,
19
+ sign: "df67936f918887b2aa31688a77a10fe1",
20
+ ))
21
+
22
+ expect(confirmation.valid?).to be_truthy
23
+ end
24
+
25
+ it "validates signature" do
26
+ confirmation = PayU::Confirmation.new(params.merge(
27
+ reference_sale: "TestPayU05",
28
+ value: "150.26",
29
+ state_pol: PayU::Order::APPROVED,
30
+ sign: "1d95778a651e11a0ab93c2169a519cd6",
31
+ ))
32
+
33
+ expect(confirmation.valid?).to be_truthy
34
+ end
35
+
36
+ private def params
37
+ {
38
+ account_id: 508_028,
39
+ currency: :USD,
40
+ }
41
+ end
42
+ end
@@ -0,0 +1,55 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe PayU::Form do
4
+ before do
5
+ PayU.reset
6
+ end
7
+
8
+ # Example from http://developers.payulatam.com/es/web_checkout/integration.html
9
+ it "validates signature" do
10
+ order = PayU::Order.new(
11
+ account_id: PayU.configuration.account_ids[:PA],
12
+ reference_code: "TestPayU",
13
+ amount: 20_000,
14
+ currency: :COP,
15
+ )
16
+
17
+ expect(order.form.signature).to eq("7ee7cf808ce6a39b17481c54f2c57acc")
18
+ end
19
+
20
+ it "generates params" do
21
+ response_url = "http://www.test.com/response"
22
+ confirmation_url = "http://www.test.com/confirmation"
23
+ account_id = PayU.configuration.account_ids[:CO]
24
+ description = "Test PAYU"
25
+ amount = 20_000
26
+ currency = :COP
27
+ PayU.configure do |config|
28
+ config.response_url = response_url
29
+ config.confirmation_url = confirmation_url
30
+ end
31
+ form = PayU::Order.new(
32
+ account_id: account_id,
33
+ description: description,
34
+ reference_code: "TestPayU",
35
+ amount: amount,
36
+ currency: currency,
37
+ tax: 3_193,
38
+ tax_return_base: 16_806,
39
+ ).form
40
+
41
+ expect(form.params).to be_a(Hash)
42
+ expect(form.params[:action]).to eq(
43
+ "https://sandbox.checkout.payulatam.com/ppp-web-gateway-payu/",
44
+ )
45
+ expect(form.params[:fields][:merchantId]).to eq(PayU.configuration.merchant_id)
46
+ expect(form.params[:fields][:accountId]).to eq(account_id)
47
+ expect(form.params[:fields][:description]).to eq(description)
48
+ expect(form.params[:fields][:amount]).to eq(amount)
49
+ expect(form.params[:fields][:currency]).to eq(currency)
50
+ expect(form.params[:fields][:signature]).to eq("7ee7cf808ce6a39b17481c54f2c57acc")
51
+ expect(form.params[:fields][:test]).to eq("1")
52
+ expect(form.params[:fields][:responseUrl]).to eq(response_url)
53
+ expect(form.params[:fields][:confirmationUrl]).to eq(confirmation_url)
54
+ end
55
+ end
@@ -0,0 +1,50 @@
1
+ require "spec_helper"
2
+ require "fixtures/response"
3
+
4
+ RSpec.describe PayU::Response do
5
+ it "creates object from callback" do
6
+ response = PayU::Response.new(Fixtures.response)
7
+
8
+ expect(response.order.reference_code).to eq(Fixtures.response[:referenceCode])
9
+ expect(response.order.transaction_id).to eq(Fixtures.response[:transactionId])
10
+ expect(response.valid?).to be_truthy
11
+ end
12
+
13
+ # Example from http://developers.payulatam.com/es/web_checkout/integration.html
14
+ it "validates signature" do
15
+ response = PayU::Response.new(params.merge(
16
+ TX_VALUE: 150.25,
17
+ signature: "00286dc735bd9eaa8ae3a3a4cbb40688",
18
+ ))
19
+
20
+ expect(response.valid?).to be_truthy
21
+ end
22
+
23
+ it "validates signature" do
24
+ response = PayU::Response.new(params.merge(
25
+ TX_VALUE: 150.35,
26
+ signature: "9df2bb60e2838170009040982967923f",
27
+ ))
28
+
29
+ expect(response.valid?).to be_truthy
30
+ end
31
+
32
+ it "validates signature" do
33
+ response = PayU::Response.new(params.merge(
34
+ TX_VALUE: 150.34,
35
+ signature: "779f163be9347a691bcdb25064644795",
36
+ ))
37
+
38
+ expect(response.valid?).to be_truthy
39
+ end
40
+
41
+
42
+ private def params
43
+ {
44
+ account_id: 508_028,
45
+ referenceCode: "TestPayU04",
46
+ currency: :USD,
47
+ transactionState: PayU::Order::DECLINED,
48
+ }
49
+ end
50
+ end
@@ -0,0 +1,7 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe PayU do
4
+ it "has a version number" do
5
+ expect(PayU::VERSION).not_to be nil
6
+ end
7
+ end
@@ -0,0 +1,31 @@
1
+ require "simplecov"
2
+ require "coveralls"
3
+
4
+ SimpleCov.formatters = [
5
+ SimpleCov::Formatter::HTMLFormatter,
6
+ Coveralls::SimpleCov::Formatter,
7
+ ]
8
+
9
+ SimpleCov.start
10
+ Coveralls.wear!
11
+
12
+ require "pry"
13
+ require "bundler/setup"
14
+ require "pay_u"
15
+
16
+ if ENV["CIRCLE_ARTIFACTS"]
17
+ dir = File.join(ENV["CIRCLE_ARTIFACTS"], "coverage")
18
+ SimpleCov.coverage_dir(dir)
19
+ end
20
+
21
+ RSpec.configure do |config|
22
+ # Enable flags like --only-failures and --next-failure
23
+ config.example_status_persistence_file_path = ".rspec_status"
24
+
25
+ # Disable RSpec exposing methods globally on `Module` and `main`
26
+ config.disable_monkey_patching!
27
+
28
+ config.expect_with :rspec do |c|
29
+ c.syntax = :expect
30
+ end
31
+ end
metadata ADDED
@@ -0,0 +1,236 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: payu-latam
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Slang
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-01-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: virtus
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.15'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.15'
41
+ - !ruby/object:Gem::Dependency
42
+ name: byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: coveralls
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.12'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.12'
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: '3.6'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.6'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.7'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.7'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec_junit_formatter
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: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.57'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.57'
139
+ - !ruby/object:Gem::Dependency
140
+ name: simplecov
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: webmock
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '1.9'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '1.9'
167
+ description: 'Accept payments with PayU Latam: http://developerspec.payulatam.com/es/.'
168
+ email: engineering@slang.com
169
+ executables:
170
+ - console
171
+ - setup
172
+ extensions: []
173
+ extra_rdoc_files: []
174
+ files:
175
+ - ".circleci/config.yml"
176
+ - ".gitignore"
177
+ - ".rubocop.yml"
178
+ - Gemfile
179
+ - LICENSE
180
+ - README.md
181
+ - bin/console
182
+ - bin/setup
183
+ - lib/pay_u.rb
184
+ - lib/pay_u/configuration.rb
185
+ - lib/pay_u/confirmation.rb
186
+ - lib/pay_u/constants.rb
187
+ - lib/pay_u/form.rb
188
+ - lib/pay_u/order.rb
189
+ - lib/pay_u/response.rb
190
+ - lib/pay_u/signer/base.rb
191
+ - lib/pay_u/signer/confirmation.rb
192
+ - lib/pay_u/signer/form.rb
193
+ - lib/pay_u/signer/response.rb
194
+ - lib/pay_u/version.rb
195
+ - payu-latam.gemspec
196
+ - spec/fixtures/confirmation.rb
197
+ - spec/fixtures/response.rb
198
+ - spec/pay_u/configuration_spec.rb
199
+ - spec/pay_u/confirmation_spec.rb
200
+ - spec/pay_u/form_spec.rb
201
+ - spec/pay_u/response_spec.rb
202
+ - spec/pay_u_spec.rb
203
+ - spec/spec_helper.rb
204
+ homepage: https://slangapp.com
205
+ licenses:
206
+ - MIT
207
+ metadata: {}
208
+ post_install_message:
209
+ rdoc_options: []
210
+ require_paths:
211
+ - lib
212
+ required_ruby_version: !ruby/object:Gem::Requirement
213
+ requirements:
214
+ - - ">="
215
+ - !ruby/object:Gem::Version
216
+ version: 2.1.0
217
+ required_rubygems_version: !ruby/object:Gem::Requirement
218
+ requirements:
219
+ - - ">="
220
+ - !ruby/object:Gem::Version
221
+ version: '0'
222
+ requirements: []
223
+ rubyforge_project:
224
+ rubygems_version: 2.7.8
225
+ signing_key:
226
+ specification_version: 4
227
+ summary: Ruby bindings for the PayU Latam API
228
+ test_files:
229
+ - spec/fixtures/confirmation.rb
230
+ - spec/fixtures/response.rb
231
+ - spec/pay_u/configuration_spec.rb
232
+ - spec/pay_u/confirmation_spec.rb
233
+ - spec/pay_u/form_spec.rb
234
+ - spec/pay_u/response_spec.rb
235
+ - spec/pay_u_spec.rb
236
+ - spec/spec_helper.rb