easy_pay_u_latam 0.1.20 → 0.1.27

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 170182b7358dc7f68f90de66fb2889ac7147f79c87cbd044ad30d5711ad40db0
4
- data.tar.gz: b5f9d50cf009589a175417a73c2472a5e89649544a24684b238cf94303776657
3
+ metadata.gz: 8e6daef3c30061128c0dc665d6a4d0f638c26d16ec6b542c1426089426b1ad3a
4
+ data.tar.gz: 5fdab63ab338bccb5188ae23a0377d124bff758b236dd32ce667c9a69c799ae3
5
5
  SHA512:
6
- metadata.gz: a20619fc34009f743dea0ae3427654bae4c47ba3ad831fafa7eb598d5a12b2b1c6514cf1b895c85f17775e27840e2736d89a5005aa555052a49b5656e224e429
7
- data.tar.gz: ae097259e80d99d3c87d96ca4e5a8f1f43460d4badfe7fcf138005839342a44f18fecef5d8afbe90985182b5069d062d08d7729f541800772b9fd9b522e5b2ae
6
+ metadata.gz: c4986995ee429829e73c4a168da540b87fed5929f025e1cf0795d6e6021a9caf9ab588e26a889b7cfc413ec48bc77b7180cdf8c034d261613ce9cb7aaeac5661
7
+ data.tar.gz: 3f3f696e47bd6ca13ea003536f8b4fa74e0a726fa3c0e13b51af77fb15198d945513b67505b37ced4827e8e2e59350cedac73b4d6bacddca8cef5fb8a1be4d3a
data/README.md CHANGED
@@ -35,7 +35,7 @@ $ rails g migration AddPayUFieldsToUsers payu_default_card:string payu_customer_
35
35
 
36
36
  Only run this when recurrent payments are ON, extra fields for recurrent payments on payments table, you must run the following migration.
37
37
  ```bash
38
- $ rails g migration AddRecurrentPaymentsToEasyPayULatamPayuPayments payu_plan_id:string payu_plan_code:string payu_customer_id:string payu_subscription_id:string trial_days:integer payu_credit_card_token:string
38
+ $ rails g migration AddRecurrentPaymentsToEasyPayULatamPayuPayments payu_plan_id:string payu_plan_code:string payu_customer_id:string payu_subscription_id:string trial_days:integer payu_credit_card_token:string additional_charges_data:string
39
39
  ```
40
40
 
41
41
  If you want to keep a reference to plans, before this you must have created a plan model on your project, you can run the following migration (User only when recurrent payments are ON).
@@ -68,6 +68,16 @@ EasyPayULatam.configure do |config|
68
68
  #Pay U will consume a Web Service and it can not be in localhost, you most use something like ngrok
69
69
  config.test_root_url = "ROOT URL FOR TESTING"
70
70
  config.currency_precision = 2 #By default is 0 for colombian peso
71
+ config.testing = true #Set false in production
72
+ end
73
+
74
+ # This keys are different, the recursive API use other keys
75
+ EasyPayULatam::RApi.configure do |config|
76
+ config.api_login = 'YOUR KEY'
77
+ config.api_key = 'YOUR KEY'
78
+ config.account_id = 'YOUR PAY U ACCOUNT ID'
79
+ config.sandbox = true #Set false in production
80
+ config.api_version = "v4.3"
71
81
  end
72
82
  ```
73
83
 
@@ -0,0 +1,30 @@
1
+ module EasyPayULatam
2
+ class Api::V1::PayUAdditionalChargesController < ApiController
3
+
4
+ acts_as_token_authentication_handler_for User
5
+
6
+ def create
7
+
8
+ addcharge = current_user.last_payment.add_charge(params)
9
+
10
+ unless addcharge.response.blank?
11
+ render status: 200, json: {message: "ok"}
12
+ else
13
+ msg = addcharge.error["errorList"].blank? ? addcharge.error["description"] : addcharge.error["errorList"].to_sentence
14
+ render status: 411, json: {message: msg }
15
+ end
16
+ end
17
+
18
+ def destroy
19
+
20
+ if current_user.last_payments.count > 0
21
+ current_user.last_payment.remove_charge(params[:charge_id])
22
+
23
+ render status: 200, json: {message: "¡Cargo extra cancelado correctamente, tu plan estará activo por el periodo que ya habías pagado!"}
24
+ else
25
+ render status: 411, json: {message: "No tienes cargos extra para cancelar"}
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -4,15 +4,14 @@ module EasyPayULatam
4
4
  acts_as_token_authentication_handler_for User
5
5
 
6
6
  def index
7
- render status: 200, json: {subscriptions: current_user.all_payments.first(30)}
8
- # client = RApi::Client.new current_user.pay_u_costumer_id
9
- # subs = RApi::Subscription.new client
10
- #
11
- # unless subs.response["recurringBillList"].blank?
12
- # render status: 200, json: {subscriptions: subs.response["recurringBillList"].last(30)}
13
- # else
14
- # render status: 200, json: {subscriptions: []}
15
- # end
7
+ client = RApi::Client.new current_user.pay_u_costumer_id
8
+ subs = RApi::Subscription.new client
9
+
10
+ unless subs.response["recurringBillList"].blank?
11
+ render status: 200, json: {subscriptions: current_user.all_payments.first(30), subscriptions_api: subs.response["recurringBillList"].last(30)}
12
+ else
13
+ render status: 200, json: {subscriptions: [], subscriptions_api: []}
14
+ end
16
15
  end
17
16
 
18
17
  def create
@@ -18,5 +18,60 @@ module EasyPayULatam
18
18
  self.status == PENDING
19
19
  end
20
20
 
21
+ def add_charge(params, user)
22
+ @payUConfig = EasyPayULatam.configuration
23
+
24
+ client = RApi::Client.new user.pay_u_costumer_id
25
+ addcharge = RApi::AdditionalCharge.new client, self.reference_recurring_payment
26
+ addcharge.params = {
27
+ "description" => params[:description],
28
+ "additionalValues" => [
29
+ {
30
+ "name" => "ITEM_VALUE",
31
+ "value" => params[:value],
32
+ "currency" => "COP"
33
+ },
34
+ {
35
+ "name" => "ITEM_TAX",
36
+ "value" => "0",
37
+ "currency" => "COP"
38
+ },
39
+ {
40
+ "name" => "ITEM_TAX_RETURN_BASE",
41
+ "value" => "0",
42
+ "currency" => "COP"
43
+ }
44
+ ]
45
+ }
46
+
47
+ addcharge.create!
48
+
49
+ unless addcharge.response["id"].blank?
50
+ self.additional_charges_data = "#{self.additional_charges_data}|#{addcharge.response["id"]}·#{Date.today}"
51
+ end
52
+
53
+ addcharge
54
+ end
55
+
56
+ def get_additional_charges
57
+ charges = []
58
+ self.additional_charges_data.split("|").each do |charge|
59
+ data = charge.split("·")
60
+ charges.push({id: data[0], date: data[1]})
61
+ end
62
+ charges
63
+ end
64
+
65
+ def remove_charge(id, user)
66
+ @payUConfig = EasyPayULatam.configuration
67
+
68
+ client = RApi::Client.new user.pay_u_costumer_id
69
+ addcharge = RApi::AdditionalCharge.new client, self.reference_recurring_payment
70
+
71
+ addcharge.delete id
72
+
73
+ addcharge
74
+ end
75
+
21
76
  end
22
77
  end
@@ -14,6 +14,7 @@ EasyPayULatam::Engine.routes.draw do
14
14
  resources :pay_u_clients, only: [:create]
15
15
  resources :pay_u_plans, only: [:index]
16
16
  resources :pay_u_subscriptions, only: [:index, :show, :create, :update, :destroy]
17
+ resources :pay_u_additional_charges, only: [:create, :destroy]
17
18
  end
18
19
  end
19
20
 
@@ -6,6 +6,7 @@ require "easy_pay_u_latam/r_api/plan"
6
6
  require "easy_pay_u_latam/r_api/card"
7
7
  require "easy_pay_u_latam/r_api/client"
8
8
  require "easy_pay_u_latam/r_api/subscription"
9
+ require "easy_pay_u_latam/r_api/additional_charge"
9
10
 
10
11
  module EasyPayULatam
11
12
  class << self
@@ -3,7 +3,7 @@ module EasyPayULatam
3
3
  class << self
4
4
  require "base64"
5
5
  # NOTA: definir si dejar estos campos como accessors
6
- attr_accessor :api_login, :api_key, :account_id, :sandbox
6
+ attr_accessor :api_login, :api_key, :account_id, :sandbox, :api_version
7
7
  attr_reader :base_url
8
8
 
9
9
  # recibe un bloque inicializador de variables de configuración de payu como la
@@ -34,6 +34,7 @@ module EasyPayULatam
34
34
  # config.api_key = '4Vj8eK4rloUd272L48hsrarnUA'
35
35
  # config.account_id = '512321'
36
36
  # config.sandbox = true
37
+ # config.api_version = "v4.3"
37
38
  # end
38
39
 
39
40
  # production
@@ -42,6 +43,7 @@ module EasyPayULatam
42
43
  # config.api_key = 'ZNl7g0L2H54Y9ZVn51keXS2l07'
43
44
  # config.account_id = '762507'
44
45
  # config.sandbox = false
46
+ # config.api_version = "v4.3"
45
47
  # end
46
48
 
47
49
  end
@@ -0,0 +1,42 @@
1
+ module EasyPayULatam
2
+ module RApi
3
+ class AdditionalCharge < Request
4
+ attr_reader :url, :plan, :customer, :card, :sub_id
5
+ attr_accessor :resource, :params
6
+
7
+ def initialize(customer, sub_id)
8
+ @customer = customer
9
+ @sub_id = sub_id
10
+ @customer = customer.response if !customer.nil?
11
+ # @callback_url = callback_url
12
+ @params = {}
13
+ return if @customer.nil?
14
+ # load("")
15
+ end
16
+
17
+ def create_url
18
+ @url = RApi.base_url + "/rest/#{RApi.api_version}/subscriptions/#{@sub_id}/recurringBillItems}"
19
+ end
20
+
21
+ def url
22
+ @url = RApi.base_url + "/rest/#{RApi.api_version}/recurringBillItems/"
23
+ end
24
+
25
+ def create!
26
+ create_url
27
+ super
28
+ end
29
+
30
+ def load(id)
31
+ url
32
+ super
33
+ end
34
+
35
+ def delete(id)
36
+ url
37
+ super
38
+ end
39
+
40
+ end
41
+ end
42
+ end
@@ -21,13 +21,13 @@ module EasyPayULatam
21
21
 
22
22
  # llena la variable local y super con la url de este recurso
23
23
  def url
24
- @url ||= RApi.base_url + "/rest/v4.9/creditCards/"
24
+ @url ||= RApi.base_url + "/rest/#{RApi.api_version}/creditCards/"
25
25
  end
26
26
 
27
27
  # el recurso de tarjeta necesita en algunos casos alterar la URL para incluir información
28
28
  # del customer, por eso se crea este metodo con la url necesario
29
29
  def customer_url
30
- @url = RApi.base_url + "/rest/v4.9/customers/#{@customer['id']}/creditCards/"
30
+ @url = RApi.base_url + "/rest/#{RApi.api_version}/customers/#{@customer['id']}/creditCards/"
31
31
  end
32
32
 
33
33
  # se sobreescribe el metodo crear de request
@@ -15,7 +15,7 @@ module EasyPayULatam
15
15
 
16
16
  # url base
17
17
  def url
18
- @url = RApi.base_url + '/rest/v4.9/customers/'
18
+ @url = RApi.base_url + "/rest/#{RApi.api_version}/customers/"
19
19
  end
20
20
 
21
21
  private
@@ -34,7 +34,7 @@ module PayuLatam
34
34
  end
35
35
 
36
36
  def url
37
- @url = PayuLatam.base_url + '/rest/v4.9/recurringBill'
37
+ @url = PayuLatam.base_url + "/rest/#{RApi.api_version}/recurringBill"
38
38
  end
39
39
 
40
40
  def customer_url
@@ -50,4 +50,4 @@ module PayuLatam
50
50
  @url = url "?customerId=#{@id}&dateBegin=#{@dateBegin}&dateFinal=#{@dateFinal}"
51
51
  end
52
52
  end
53
- end
53
+ end
@@ -28,7 +28,7 @@ module EasyPayULatam
28
28
  end
29
29
 
30
30
  def url
31
- @url = RApi.base_url + '/rest/v4.9/plans/'
31
+ @url = RApi.base_url + "/rest/#{RApi.api_version}/plans/"
32
32
  end
33
33
 
34
34
  private
@@ -14,11 +14,11 @@ module EasyPayULatam
14
14
  end
15
15
 
16
16
  def invoice_url
17
- @url = RApi.base_url + "/rest/v4.9/recurringBill?customerId=#{@customer['id']}"
17
+ @url = RApi.base_url + "/rest/#{RApi.api_version}/recurringBill?customerId=#{@customer['id']}"
18
18
  end
19
19
 
20
20
  def url
21
- @url = RApi.base_url + '/rest/v4.9/subscriptions/'
21
+ @url = RApi.base_url + "/rest/#{RApi.api_version}/subscriptions/"
22
22
  end
23
23
 
24
24
  def create!
@@ -31,7 +31,7 @@ module EasyPayULatam
31
31
  super
32
32
  end
33
33
 
34
- def delete(token)
34
+ def delete(id)
35
35
  url
36
36
  super
37
37
  end
@@ -1,3 +1,3 @@
1
1
  module EasyPayULatam
2
- VERSION = '0.1.20'
2
+ VERSION = '0.1.27'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_pay_u_latam
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.20
4
+ version: 0.1.27
5
5
  platform: ruby
6
6
  authors:
7
7
  - DEVPENGUIN
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-13 00:00:00.000000000 Z
11
+ date: 2020-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rails-assets-sweetalert2
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: sweet-alert2-rails
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -146,6 +160,7 @@ files:
146
160
  - app/assets/stylesheets/easy_pay_u_latam/styles.css
147
161
  - app/assets/stylesheets/easy_pay_u_latam/subscriptions/application.scss
148
162
  - app/assets/stylesheets/easy_pay_u_latam/subscriptions/card.css
163
+ - app/controllers/easy_pay_u_latam/api/v1/pay_u_additional_charges_controller.rb
149
164
  - app/controllers/easy_pay_u_latam/api/v1/pay_u_cards_controller.rb
150
165
  - app/controllers/easy_pay_u_latam/api/v1/pay_u_clients_controller.rb
151
166
  - app/controllers/easy_pay_u_latam/api/v1/pay_u_payments_controller.rb
@@ -184,6 +199,7 @@ files:
184
199
  - lib/easy_pay_u_latam/Configuration.rb
185
200
  - lib/easy_pay_u_latam/engine.rb
186
201
  - lib/easy_pay_u_latam/r_api.rb
202
+ - lib/easy_pay_u_latam/r_api/additional_charge.rb
187
203
  - lib/easy_pay_u_latam/r_api/card.rb
188
204
  - lib/easy_pay_u_latam/r_api/client.rb
189
205
  - lib/easy_pay_u_latam/r_api/invoice.rb