pagseguro-charge 0.5

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: 838511272ce92244863caf0724dd9191784f67a34130e35e8a6518d49eb1d06b
4
+ data.tar.gz: 84b8dac9486fe9fbdd48f2fe7613035ceb98b69f601ca41a67bd79f14195b50e
5
+ SHA512:
6
+ metadata.gz: 7b4b9eabe0aeab031cb3bb659fef89467dc60d83881db573fc025de3373c9dd222d12dd7f4ac996affd58b28f92041e8a79e053e544477e98e5960461fb9378d
7
+ data.tar.gz: aa45a5b6a6938ef9d76f69dc62dad1f3e0e24e41f8f624bdc1950ade516fdd7f72ce7cc74b9d72e1eddd1db758481e4c690a18e3a54dcfed0e64179c8d2cd135
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ # Ignore all files with the .gem extension
13
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.7
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in pagseguro-charge.gemspec
6
+ gemspec
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ pagseguro-charge (0.5)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ rake (10.5.0)
11
+ rspec (3.8.0)
12
+ rspec-core (~> 3.8.0)
13
+ rspec-expectations (~> 3.8.0)
14
+ rspec-mocks (~> 3.8.0)
15
+ rspec-core (3.8.0)
16
+ rspec-support (~> 3.8.0)
17
+ rspec-expectations (3.8.2)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.8.0)
20
+ rspec-mocks (3.8.0)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.8.0)
23
+ rspec-support (3.8.0)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler (~> 1.16)
30
+ pagseguro-charge!
31
+ rake (~> 10.0)
32
+ rspec (~> 3.0)
33
+
34
+ BUNDLED WITH
35
+ 1.17.2
@@ -0,0 +1,23 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Rafael Pitoni
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
22
+
23
+ https://devs.pagseguro.uol.com.br/v1/docs/charge-api
@@ -0,0 +1,39 @@
1
+ # Pagseguro::Charge
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/pagseguro/charge`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'pagseguro-charge'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install pagseguro-charge
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/pagseguro-charge.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -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
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "pagseguro/charge"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,23 @@
1
+ require "pagseguro/charge/version"
2
+ require "pagseguro/charge/charge_request"
3
+ require "pagseguro/charge/charge_response"
4
+ require "pagseguro/charge/payment_method"
5
+ require "pagseguro/charge/credit_card"
6
+ require "pagseguro/charge/summary"
7
+ require "pagseguro/charge/boleto"
8
+ require "pagseguro/charge/address"
9
+ require "pagseguro/charge/link"
10
+ require "pagseguro/charge/instruction_lines"
11
+ require "pagseguro/charge/payment_response"
12
+ require "pagseguro/charge/error_message"
13
+ require "pagseguro/charge/amount"
14
+ require "pagseguro/charge/holder"
15
+ require "pagseguro/charge/connect/charge_connect"
16
+
17
+ module Pagseguro
18
+ module Charge
19
+ def self.root_path
20
+ File.dirname __dir__
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,63 @@
1
+ module Pagseguro
2
+ module Charge
3
+ # Credit card data
4
+
5
+ class Address
6
+ attr_accessor :country,
7
+ :region,
8
+ :region_code,
9
+ :city,
10
+ :postal_code,
11
+ :street,
12
+ :number,
13
+ :locality
14
+
15
+
16
+ def initialize(args = {})
17
+ @country = args[:country]
18
+ @region = args[:region]
19
+ @region_code = args[:region_code]
20
+ @city = args[:city]
21
+ @postal_code = args[:postal_code]
22
+ @street = args[:street]
23
+ @number = args[:number]
24
+ @locality = args[:locality]
25
+ end
26
+
27
+ def to_json(*options)
28
+ hash = as_json(*options)
29
+ hash.reject! {|k,v| v.nil?}
30
+ hash.to_json(*options)
31
+ end
32
+
33
+ def self.fill_from_json(data)
34
+ return if data.nil?
35
+
36
+ address = new
37
+ address.country = data["country"]
38
+ address.region = data["region"]
39
+ address.region_code = data["region_code"]
40
+ address.city = data["city"]
41
+ address.postal_code = data["postal_code"]
42
+ address.street = data["street"]
43
+ address.number = data["number"]
44
+ address.locality = data["locality"]
45
+ address
46
+ end
47
+
48
+ def as_json(options={})
49
+ {
50
+ country: @country,
51
+ region: @region,
52
+ region_code: @region_code,
53
+ city: @city,
54
+ postal_code: @postal_code,
55
+ street: @street,
56
+ number: @number,
57
+ locality: @locality
58
+ }
59
+ end
60
+ end
61
+
62
+ end
63
+ end
@@ -0,0 +1,42 @@
1
+ module Pagseguro
2
+ module Charge
3
+ # Credit card data
4
+
5
+ class Amount
6
+ attr_accessor :value,
7
+ :currency,
8
+ :summary
9
+
10
+ def initialize(args = {})
11
+ @value = args[:value]
12
+ @currency = args[:currency]
13
+ @summary = args[:summary]
14
+ end
15
+
16
+ def to_json(*options)
17
+ hash = as_json(*options)
18
+ hash.reject! {|k,v| v.nil?}
19
+ hash.to_json(*options)
20
+ end
21
+
22
+ def self.fill_from_json(data)
23
+ return if data.nil?
24
+
25
+ amount = new
26
+ amount.currency = data["currency"]
27
+ amount.value = data["value"]
28
+ amount.summary = Summary.fill_from_json(data["summary"])
29
+ amount
30
+
31
+ end
32
+
33
+ def as_json(options={})
34
+ {
35
+ value: @value,
36
+ currency: @currency,
37
+ summary: @summary
38
+ }
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,56 @@
1
+ module Pagseguro
2
+ module Charge
3
+ # Credit card data
4
+ #
5
+ # @attr [Long] number Credit card number
6
+ # @attr [integer] exp_month Credit card expiration month
7
+ # @attr [Integer] exp_year Credit card expiration year
8
+ # @attr [String] security_code Credit card security_code
9
+ # @attr [String] brand Credit card brand
10
+ class Boleto
11
+ attr_accessor :due_date,
12
+ :instruction_lines,
13
+ :holder,
14
+ #response
15
+ :id,
16
+ :barcode,
17
+ :formatted_barcode
18
+
19
+ def initialize(args = {})
20
+ @due_date = args[:due_date]
21
+ @instruction_lines = args[:instruction_lines]
22
+ @holder = args[:holder]
23
+ end
24
+
25
+ def to_json(*options)
26
+ hash = as_json(*options)
27
+ hash.reject! {|k,v| v.nil?}
28
+ hash.to_json(*options)
29
+ end
30
+
31
+ def self.fill_from_json(data)
32
+ return if data.nil?
33
+
34
+ boleto = new
35
+ boleto.due_date = data["due_date"]
36
+ boleto.instruction_lines = InstructionLines.fill_from_json(data["instruction_lines"])
37
+ boleto.holder = Holder.fill_from_json(data["holder"])
38
+ boleto.barcode = data["barcode"]
39
+ boleto.id = data["id"]
40
+ boleto.formatted_barcode = data["formatted_barcode"]
41
+ boleto
42
+ end
43
+
44
+ def as_json(options={})
45
+ {
46
+ id: @id,
47
+ due_date: @due_date,
48
+ instruction_lines: @instruction_lines,
49
+ barcode: @barcode,
50
+ formatted_barcode: @formatted_barcode,
51
+ holder: @holder
52
+ }
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,63 @@
1
+ module Pagseguro
2
+ module Charge
3
+ # Payment data
4
+ #
5
+ # @attr [String] reference An arbitrary code provided for control, like an e-commerce order number
6
+ # @attr [String] payment_methods List of the different payment methods being using in a charge
7
+ # @attr [String] currency Three-letter ISO currency code, in uppercase. For now, only Brazilian Real is supported (“BRL”), must be 3 characters.
8
+ # @attr [String] description An arbitrary string attached to the object. Often useful for displaying to users, maximum 64 characters.
9
+ # @attr [String] metadata Set of key-value pairs that you can attach to an object. This can be useful for storing additional information about the object in a structured format.
10
+ class ChargeRequest
11
+ TYPE_CREDITCARD = "CREDIT_CARD"
12
+ TYPE_BOLETO = "BOLETO"
13
+
14
+ attr_accessor :reference_id,
15
+ :payment_method,
16
+ :description,
17
+ :amount,
18
+ :id
19
+
20
+
21
+ def initialize(args = {})
22
+ @id = args[:id]
23
+ @reference_id = args[:reference_id]
24
+ @payment_method = args[:payment_method]
25
+ @amount = args[:amount]
26
+ @description = args[:description]
27
+ end
28
+
29
+ def to_json(*options)
30
+ hash = as_json(*options)
31
+ hash.reject! {|k,v| v.nil?}
32
+ hash.to_json(*options)
33
+ end
34
+
35
+ def self.fill_from_json(data)
36
+ return if data.nil?
37
+
38
+ payment = new
39
+
40
+ payment.id = data["id "]
41
+ payment.reference_id = data["reference_id"]
42
+ payment.payment_method = PaymentMethod.fill_from_json(data["payment_method"])
43
+ payment.amount = Amount.fill_from_json(data["amount"])
44
+ payment.description = data["description"]
45
+
46
+ payment
47
+ end
48
+
49
+
50
+ def as_json(options={})
51
+ {
52
+ id: @id,
53
+ reference_id: @reference_id,
54
+ payment_method: @payment_method,
55
+ description: @description,
56
+ amount: @amount
57
+ }
58
+ end
59
+ end
60
+
61
+
62
+ end
63
+ end
@@ -0,0 +1,90 @@
1
+ module Pagseguro
2
+ module Charge
3
+ class ChargeResponse
4
+
5
+ attr_accessor :reference_id,
6
+ :id,
7
+ :status,
8
+ :created_at,
9
+ :description,
10
+ :amount,
11
+ :payment_response,
12
+ :payment_method,
13
+ :error_messages,
14
+ :links
15
+
16
+ STATUS_AUTHORIZED = 'AUTHORIZED'.freeze
17
+ STATUS_DECLINED = 'DECLINED'.freeze
18
+ STATUS_PAID = 'PAID'.freeze
19
+ STATUS_CANCELED = 'CANCELED'.freeze
20
+ STATUS_PENDING = 'WAITING'.freeze
21
+
22
+ def initialize
23
+ end
24
+
25
+ def to_json(*options)
26
+ hash = as_json(*options)
27
+ hash.reject! {|k,v| v.nil?}
28
+ hash.to_json(*options)
29
+ end
30
+
31
+ def self.fill_from_json(data)
32
+ return if data.nil?
33
+
34
+ charge_response = new
35
+
36
+ charge_response.reference_id = data["reference_id"]
37
+ charge_response.id = data["id"]
38
+ charge_response.status = data["status"]
39
+ charge_response.amount = Amount.fill_from_json(data["amount"])
40
+ charge_response.created_at = data["created_at"]
41
+ charge_response.description = data["description"]
42
+ charge_response.payment_response = PaymentResponse.fill_from_json(data["payment_response"])
43
+ charge_response.payment_method = PaymentMethod.fill_from_json(data["payment_method"])
44
+
45
+ charge_response.error_messages = data["error_messages"].map{|a| ErrorMessage.fill_from_json(a)} unless data["error_messages"].blank?
46
+ charge_response.links = data["links"].map{|a| Link.fill_from_json(a)} unless data["links"].blank?
47
+
48
+ charge_response
49
+ end
50
+
51
+
52
+ def as_json(options={})
53
+ {
54
+ id: @id,
55
+ reference_id: @reference_id,
56
+ status: @status,
57
+ amount: @amount,
58
+ created_at: @created_at,
59
+ description: @description,
60
+ payment_response: @payment_response,
61
+ payment_method: @payment_method,
62
+ error_messages: @error_messages,
63
+ links: @links
64
+ }
65
+ end
66
+
67
+ def paid?
68
+ @status == STATUS_PAID
69
+ end
70
+ def authorized?
71
+ @status == STATUS_AUTHORIZED
72
+ end
73
+
74
+ def declined?
75
+ @status == STATUS_DECLINED
76
+ end
77
+
78
+ def captured?
79
+ @status == STATUS_PAID
80
+ end
81
+
82
+ def canceled?
83
+ @status == STATUS_CANCELED
84
+ end
85
+ end
86
+
87
+
88
+
89
+ end
90
+ end
@@ -0,0 +1,95 @@
1
+ module Pagseguro
2
+ module Charge
3
+ module Connect
4
+ class ChargeConnect
5
+ PRODUCTION_URL = 'https://api.pagseguro.com/charges'
6
+ SANDBOX_URL = 'https://sandbox.api.pagseguro.com/charges'
7
+
8
+ attr_accessor :authorization_token, :sandbox
9
+ private :authorization_token
10
+
11
+ def initialize(authorization_token, sandbox = false)
12
+ @authorization_token = authorization_token
13
+ @sandbox = sandbox
14
+ end
15
+
16
+
17
+ # creates a new charge request
18
+ def place_charge(charge_request)
19
+ data = do_connect('POST', URI.parse(@sandbox ? SANDBOX_URL : PRODUCTION_URL), charge_request.to_json)
20
+ charge_response = ChargeResponse.fill_from_json(JSON.parse(data))
21
+ charge_response
22
+ end
23
+
24
+ # retireves a charge by its id
25
+ def retrieve_by_id(charge_id)
26
+ data = do_connect('GET', URI.parse("#{@sandbox ? SANDBOX_URL : PRODUCTION_URL}/#{charge_id}"))
27
+ charge_response = ChargeResponse.fill_from_json(JSON.parse(data))
28
+ charge_response
29
+ end
30
+
31
+ # retireves a charge by reference number
32
+ def retrieve_by_reference_id(reference_id)
33
+ data = do_connect('GET', URI.parse("#{@sandbox ? SANDBOX_URL : PRODUCTION_URL}?reference_id=#{reference_id}"))
34
+ charge_response = ChargeResponse.fill_from_json(JSON.parse(data))
35
+ charge_response
36
+ end
37
+
38
+ # captures an authorized payment
39
+ def capture(charge_request)
40
+ data = do_connect('POST', URI.parse("#{@sandbox ? SANDBOX_URL : PRODUCTION_URL}/#{charge_request.id}/capture"),
41
+ charge_request.to_json)
42
+ charge_response = ChargeResponse.fill_from_json(JSON.parse(data))
43
+ charge_response
44
+ end
45
+
46
+ #void/cancels a payment
47
+ def cancel(charge_request)
48
+ data = do_connect('POST', URI.parse("#{@sandbox ? SANDBOX_URL : PRODUCTION_URL}/#{charge_request.id}/cancel"),
49
+ charge_request.to_json)
50
+ charge_response = ChargeResponse.fill_from_json(JSON.parse(data))
51
+ charge_response
52
+ end
53
+
54
+
55
+ private
56
+ def do_connect(method, uri, data=nil)
57
+
58
+ http = Net::HTTP.new(uri.host, uri.port)
59
+ http.use_ssl = true
60
+
61
+ request = case method
62
+ when 'POST'
63
+ Net::HTTP::Post.new(uri)
64
+ when 'GET'
65
+ Net::HTTP::Get.new(uri)
66
+ else
67
+ Net::HTTP::Post.new(uri)
68
+ end
69
+
70
+ request["X-api-version"] = "1.0"
71
+ request["Accept"] = "application/json"
72
+ request["Cache-Control"] = "no-cache"
73
+ request["Authorization"] = "Bearer #{@authorization_token}"
74
+
75
+ if data.nil?
76
+ request["Content-Length"] = "0"
77
+ else
78
+ request.content_type = "application/json"
79
+ request.body = data
80
+ end
81
+
82
+ puts "REQUEST #{request["Authorization"]}"
83
+ puts "REQUEST BODY #{request.body}"
84
+ response = http.request(request)
85
+
86
+ # raise Error.new(data.first["Code"], data.first["Message"]) if response.code.to_i >= 400
87
+
88
+ puts "RESPONSE BODY #{response.body}"
89
+ response.body
90
+ end
91
+ end
92
+
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,63 @@
1
+ module Pagseguro
2
+ module Charge
3
+ # Credit card data
4
+ #
5
+ # @attr [Long] number Credit card number
6
+ # @attr [integer] exp_month Credit card expiration month
7
+ # @attr [Integer] exp_year Credit card expiration year
8
+ # @attr [String] security_code Credit card security_code
9
+ # @attr [String] brand Credit card brand
10
+ class CreditCard
11
+ attr_accessor :number,
12
+ :exp_month,
13
+ :exp_year,
14
+ :security_code,
15
+ :holder,
16
+ :first_digits,
17
+ :last_digits,
18
+ :brand
19
+
20
+ def initialize(args = {})
21
+ @security_code = args[:security_code]
22
+ @number = args[:number]
23
+ @exp_month = args[:exp_month]
24
+ @exp_year = args[:exp_year]
25
+ @holder = args[:holder]
26
+ end
27
+
28
+ def to_json(*options)
29
+ hash = as_json(*options)
30
+ hash.reject! {|k,v| v.nil?}
31
+ hash.to_json(*options)
32
+ end
33
+
34
+ def self.fill_from_json(data)
35
+ return if data.nil?
36
+
37
+ credit_card = new
38
+ credit_card.number = data["number"]
39
+ credit_card.exp_month = data["exp_month"]
40
+ credit_card.exp_year = data["exp_year"]
41
+ credit_card.security_code = data["security_code"]
42
+ credit_card.first_digits = data["first_digits"]
43
+ credit_card.last_digits = data["last_digits"]
44
+ credit_card.brand = data["brand"]
45
+ credit_card.holder = Holder.fill_from_json(data["holder"])
46
+ credit_card
47
+ end
48
+
49
+ def as_json(options={})
50
+ {
51
+ brand: @brand,
52
+ number: @number,
53
+ exp_year: @exp_year,
54
+ exp_month: @exp_month,
55
+ security_code: @security_code,
56
+ last_digits: @last_digits,
57
+ first_digits: @first_digits,
58
+ holder: @holder
59
+ }
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,45 @@
1
+ module Pagseguro
2
+ module Charge
3
+ class ErrorMessage
4
+ attr_accessor :code,
5
+ :message,
6
+ :info,
7
+ :description,
8
+ :parameter_name
9
+
10
+
11
+ def initialize
12
+ end
13
+
14
+ def to_json(*options)
15
+ hash = as_json(*options)
16
+ hash.reject! {|k,v| v.nil?}
17
+ hash.to_json(*options)
18
+ end
19
+
20
+ def self.fill_from_json(data)
21
+ return if data.nil?
22
+
23
+ error_message = new
24
+ error_message.info = data["info"]
25
+ error_message.code = data["code"]
26
+ error_message.message = data["message"]
27
+ error_message.description = data["description"]
28
+ error_message.parameter_name = data["parameter_name"]
29
+ error_message
30
+ end
31
+
32
+ def as_json(options={})
33
+ {
34
+ code: @code,
35
+ message: @message,
36
+ info: @info,
37
+ description: @description,
38
+ parameter_name: @parameter_name
39
+ }
40
+ end
41
+
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,50 @@
1
+ module Pagseguro
2
+ module Charge
3
+ # Credit card data
4
+ #
5
+ # @attr [Long] number Credit card number
6
+ # @attr [integer] exp_month Credit card expiration month
7
+ # @attr [Integer] exp_year Credit card expiration year
8
+ # @attr [String] security_code Credit card security_code
9
+ # @attr [String] brand Credit card brand
10
+ class Holder
11
+ attr_accessor :name,
12
+ :tax_id,
13
+ :email,
14
+ :address
15
+
16
+ def initialize(args = {})
17
+ @name = args[:name]
18
+ @tax_id = args[:tax_id]
19
+ @email = args[:email]
20
+ @address = args[:address]
21
+ end
22
+
23
+ def to_json(*options)
24
+ hash = as_json(*options)
25
+ hash.reject! {|k,v| v.nil?}
26
+ hash.to_json(*options)
27
+ end
28
+
29
+ def self.fill_from_json(data)
30
+ return if data.nil?
31
+
32
+ holder = new
33
+ holder.name = data["name"]
34
+ holder.tax_id = data["tax_id"]
35
+ holder.email = data["email"]
36
+ holder.address = Address.fill_from_json(data["address"])
37
+ holder
38
+ end
39
+
40
+ def as_json(options={})
41
+ {
42
+ name: @name,
43
+ tax_id: @tax_id,
44
+ email: @email,
45
+ address: @address
46
+ }
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,38 @@
1
+ module Pagseguro
2
+ module Charge
3
+ # Credit card data
4
+
5
+ class InstructionLines
6
+ attr_accessor :line_1,
7
+ :line_2
8
+
9
+ def initialize(args = {})
10
+ @line_1 = args[:line_1]
11
+ @line_2 = args[:line_2]
12
+ end
13
+
14
+ def to_json(*options)
15
+ hash = as_json(*options)
16
+ hash.reject! {|k,v| v.nil?}
17
+ hash.to_json(*options)
18
+ end
19
+
20
+ def self.fill_from_json(data)
21
+ return if data.nil?
22
+
23
+ instruction_line = new
24
+ instruction_line.line_1 = data["line_1"]
25
+ instruction_line.line_2 = data["line_2"]
26
+ instruction_line
27
+ end
28
+
29
+ def as_json(options={})
30
+ {
31
+ line_1: @line_1,
32
+ line_2: @line_2
33
+ }
34
+ end
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,53 @@
1
+ module Pagseguro
2
+ module Charge
3
+ class Link
4
+ attr_accessor :rel,
5
+ :href,
6
+ :media,
7
+ :type
8
+
9
+
10
+ def initialize
11
+ end
12
+
13
+ def to_json(*options)
14
+ hash = as_json(*options)
15
+ hash.reject! {|k,v| v.nil?}
16
+ hash.to_json(*options)
17
+ end
18
+
19
+ def self.fill_from_json(data)
20
+ return if data.nil?
21
+
22
+ link = new
23
+ link.rel = data["rel"]
24
+ link.href = data["href"]
25
+ link.media = data["media"]
26
+ link.type = data["type"]
27
+ link
28
+ end
29
+
30
+ def as_json(options={})
31
+ {
32
+ rel: @rel,
33
+ href: @href,
34
+ media: @media,
35
+ type: @type
36
+ }
37
+ end
38
+
39
+ def pdf?
40
+ @media == 'application/pdf'
41
+ end
42
+
43
+ def image?
44
+ @media == 'application/image'
45
+ end
46
+
47
+ def json?
48
+ @media == 'application/json'
49
+ end
50
+ end
51
+
52
+ end
53
+ end
@@ -0,0 +1,66 @@
1
+ module Pagseguro
2
+ module Charge
3
+ # TODO FAZER UMA ENTIDADE SIMPLIFICADA AQUI DE PAGAMENTO DE CARTAO
4
+ # FAZER O MESMO PRA BOLETO
5
+
6
+ # Credit card data
7
+ #
8
+ # @attr [Long] number Credit card number
9
+ # @attr [integer] exp_month Credit card expiration month
10
+ # @attr [Integer] exp_year Credit card expiration year
11
+ # @attr [String] security_code Credit card security_code
12
+ # @attr [String] brand Credit card brand
13
+ class CreditCard
14
+ attr_accessor :number,
15
+ :exp_month,
16
+ :exp_year,
17
+ :security_code,
18
+ :holder,
19
+ :first_digits,
20
+ :last_digits,
21
+ :brand
22
+
23
+ def initialize(args = {})
24
+ @security_code = args[:security_code]
25
+ @number = args[:number]
26
+ @exp_month = args[:exp_month]
27
+ @exp_year = args[:exp_year]
28
+ @holder = args[:holder]
29
+ end
30
+
31
+ def to_json(*options)
32
+ hash = as_json(*options)
33
+ hash.reject! {|k,v| v.nil?}
34
+ hash.to_json(*options)
35
+ end
36
+
37
+ def self.fill_from_json(data)
38
+ return if data.nil?
39
+
40
+ credit_card = new
41
+ credit_card.number = data["number"]
42
+ credit_card.exp_month = data["exp_month"]
43
+ credit_card.exp_year = data["exp_year"]
44
+ credit_card.security_code = data["security_code"]
45
+ credit_card.first_digits = data["first_digits"]
46
+ credit_card.last_digits = data["last_digits"]
47
+ credit_card.brand = data["brand"]
48
+ credit_card.holder = Holder.fill_from_json(data["holder"])
49
+ credit_card
50
+ end
51
+
52
+ def as_json(options={})
53
+ {
54
+ brand: @brand,
55
+ number: @number,
56
+ exp_year: @exp_year,
57
+ exp_month: @exp_month,
58
+ security_code: @security_code,
59
+ last_digits: @last_digits,
60
+ first_digits: @first_digits,
61
+ holder: @holder
62
+ }
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,59 @@
1
+ module Pagseguro
2
+ module Charge
3
+ # Payment data
4
+ #
5
+ # @attr [String] payment_method States the payment method used in the charge. For now, we only support credit cards (“credit_card”) and boleto ("boleto")
6
+ # @attr [Object] card The Credit Card object
7
+ # @attr [Integer] amount Gross amount of the charge, in cents.
8
+ # @attr [Integer] installments The number of monthly installments the card will be charged. This must be an one or two-digit integer between 1 and 12.
9
+ # @attr [Boolean] capture Represents if the charge must be created and captured. For now, ‘TRUE’ is the only supported value.
10
+ class PaymentMethod
11
+
12
+ attr_accessor :type,
13
+ :card,
14
+ :installments,
15
+ :capture,
16
+ :capture_before,
17
+ :boleto
18
+
19
+
20
+ def initialize(type = Pagseguro::Charge::ChargeRequest::TYPE_CREDITCARD)
21
+ @type = type
22
+ end
23
+
24
+ def to_json(*options)
25
+ hash = as_json(*options)
26
+ hash.reject! {|k,v| v.nil?}
27
+ hash.to_json(*options)
28
+ end
29
+
30
+ def self.fill_from_json(data)
31
+ return if data.nil?
32
+
33
+ payment_method = new
34
+
35
+ payment_method.type = data["type"]
36
+ payment_method.card = CreditCard.fill_from_json(data["card"])
37
+ payment_method.boleto = Boleto.fill_from_json(data["boleto"])
38
+ payment_method.installments = data["installments"]
39
+ payment_method.capture = data["capture"]
40
+ payment_method.capture_before = data["capture_before"]
41
+ payment_method
42
+ end
43
+
44
+
45
+ def as_json(options={})
46
+ {
47
+ type: @type,
48
+ installments: @installments,
49
+ capture: @capture,
50
+ capture_before: @capture_before,
51
+ card: @card,
52
+ boleto: @boleto,
53
+ }
54
+ end
55
+ end
56
+
57
+
58
+ end
59
+ end
@@ -0,0 +1,41 @@
1
+ module Pagseguro
2
+ module Charge
3
+ class PaymentResponse
4
+
5
+ attr_accessor :code,
6
+ :message,
7
+ :reference
8
+
9
+ def initialize
10
+ end
11
+
12
+ def to_json(*options)
13
+ hash = as_json(*options)
14
+ hash.reject! {|k,v| v.nil?}
15
+ hash.to_json(*options)
16
+ end
17
+
18
+ def self.fill_from_json(data)
19
+ return if data.nil?
20
+
21
+ payment_response = new
22
+
23
+ payment_response.code = data["code"]
24
+ payment_response.message = data["message"]
25
+ payment_response.reference = data["reference"]
26
+ payment_response
27
+ end
28
+
29
+
30
+ def as_json(options={})
31
+ {
32
+ code: @code,
33
+ message: @message,
34
+ reference: @reference
35
+ }
36
+ end
37
+ end
38
+
39
+
40
+ end
41
+ end
@@ -0,0 +1,42 @@
1
+ module Pagseguro
2
+ module Charge
3
+ # Credit card data
4
+
5
+ class Summary
6
+ attr_accessor :total,
7
+ :paid,
8
+ :refunded
9
+
10
+ def initialize(args = {})
11
+ @total = args[:total]
12
+ @paid = args[:paid]
13
+ @refunded = args[:refunded]
14
+ end
15
+
16
+ def to_json(*options)
17
+ hash = as_json(*options)
18
+ hash.reject! {|k,v| v.nil?}
19
+ hash.to_json(*options)
20
+ end
21
+
22
+ def self.fill_from_json(data)
23
+ return if data.nil?
24
+
25
+ summary = new
26
+ summary.total = data["total"]
27
+ summary.paid = data["paid"]
28
+ summary.refunded = data["refunded"]
29
+ summary
30
+ end
31
+
32
+ def as_json(options={})
33
+ {
34
+ total: @total,
35
+ paid: @paid,
36
+ refunded: @refunded
37
+ }
38
+ end
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,5 @@
1
+ module Pagseguro
2
+ module Charge
3
+ VERSION = "0.5"
4
+ end
5
+ end
@@ -0,0 +1,40 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "pagseguro/charge/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pagseguro-charge"
8
+ spec.version = Pagseguro::Charge::VERSION
9
+ spec.authors = ["PagSeguro"]
10
+ spec.email = ["pagseguro@uol.com.br"]
11
+
12
+ spec.summary = "SDK API 1.0 PagSeguro Charge"
13
+ spec.description = "Integracao com API PagSeguro Charge"
14
+ spec.homepage = "https://dev.pagseguro.uol.com.br/v4/docs"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata["allowed_push_host"] = "http://localhost"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against " \
23
+ # "public gem pushes."
24
+ # end
25
+
26
+
27
+
28
+
29
+
30
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
31
+ f.match(%r{^(test|spec|features)/})
32
+ end
33
+ spec.bindir = "exe"
34
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
+ spec.require_paths = ["lib"]
36
+
37
+ spec.add_development_dependency "bundler", "~> 1.16"
38
+ spec.add_development_dependency "rake", "~> 10.0"
39
+ spec.add_development_dependency "rspec", "~> 3.0"
40
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pagseguro-charge
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.5'
5
+ platform: ruby
6
+ authors:
7
+ - PagSeguro
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-04-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Integracao com API PagSeguro Charge
56
+ email:
57
+ - pagseguro@uol.com.br
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - Gemfile.lock
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - lib/pagseguro/charge.rb
73
+ - lib/pagseguro/charge/address.rb
74
+ - lib/pagseguro/charge/amount.rb
75
+ - lib/pagseguro/charge/boleto.rb
76
+ - lib/pagseguro/charge/charge_request.rb
77
+ - lib/pagseguro/charge/charge_response.rb
78
+ - lib/pagseguro/charge/connect/charge_connect.rb
79
+ - lib/pagseguro/charge/credit_card.rb
80
+ - lib/pagseguro/charge/error_message.rb
81
+ - lib/pagseguro/charge/holder.rb
82
+ - lib/pagseguro/charge/instruction_lines.rb
83
+ - lib/pagseguro/charge/link.rb
84
+ - lib/pagseguro/charge/payment_credit_card.rb
85
+ - lib/pagseguro/charge/payment_method.rb
86
+ - lib/pagseguro/charge/payment_response.rb
87
+ - lib/pagseguro/charge/summary.rb
88
+ - lib/pagseguro/charge/version.rb
89
+ - pagseguro-charge.gemspec
90
+ homepage: https://dev.pagseguro.uol.com.br/v4/docs
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubygems_version: 3.0.3
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: SDK API 1.0 PagSeguro Charge
113
+ test_files: []