easy_pay_u_latam 0.1.21 → 0.1.28

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: a8eee2fadb4bd7eb0470ba74dfcb62ec90ee78bf824f2ac475ff4f78355c40c9
4
- data.tar.gz: 1c45508dddbdde111502644b6002bbd946b072bfb86eb8a830a62addfdda8e2c
3
+ metadata.gz: be1a9f5b57f8b29f80c0b25b98b3f289333f76758dcc409cd1311f5820c44145
4
+ data.tar.gz: 1ac5e27558b5d49f0a67a5669ba9f51cac364f15fbe5326396db8e06a6aa9edd
5
5
  SHA512:
6
- metadata.gz: 458e3f68a3313d423748841f18315e2fecf1ecb300a1611cda682e634c440e43777c05a825bab1a1f5b0b77e5a244a316428f4f667483928816145236dcc4118
7
- data.tar.gz: 1ebbdb3e0f24f4903b69c5401f66501d4dc316965d555d3f3530484c19f1e0738c262c0fb78e11d38ea044d7b635981771a9d86a01cd75ed6322071fbae17fa1
6
+ metadata.gz: 2e0e77b13e0b7d2411146f7622463e76d73ff6b78a11a00b5c9bf742385b8835ecde045611aa0021392902e0bb5d7d344505f18aa803170ccf1cec2695fdcfe9
7
+ data.tar.gz: d5c597aab103755e374e50fb556747e5e34ec56fbf24683279a95027531b5ed7e2013afeee0c8dae39357df1b22a1fc04386d7fdcc8abdc1985fb8ae5b10a8ee
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
 
@@ -56,27 +56,27 @@
56
56
  }, 100);
57
57
 
58
58
  $('#new-credit-card-modal').on('shown.bs.modal', function () {
59
- // if (self.create_subscription_after_new_card == true){
60
- // swal({
61
- // title: 'Confirmación',
62
- // text: "Cargaremos a tu tarjeta principal mensualmente el valor del plan hasta que canceles la subscripción.",
63
- // type: 'info',
64
- // showCancelButton: true,
65
- // confirmButtonColor: '#3085d6',
66
- // cancelButtonColor: '#d33',
67
- // confirmButtonText: 'Si, continuar',
68
- // cancelButtonText: "Cancelar"
69
- // }).then((result) => {
70
- // if (result) {
71
- // $scope.$evalAsync(function(){
72
- // ('#new-credit-card-modal').modal("show");
73
- // });
74
- // }
75
- // else{
76
- // self.create_subscription_after_new_card = false;
77
- // }
78
- // });
79
- // }
59
+ if (self.create_subscription_after_new_card == true){
60
+ swal({
61
+ title: 'Confirmación',
62
+ text: "Cargaremos a tu tarjeta principal mensualmente el valor del plan hasta que canceles la subscripción.",
63
+ type: 'info',
64
+ showCancelButton: true,
65
+ confirmButtonColor: '#3085d6',
66
+ cancelButtonColor: '#d33',
67
+ confirmButtonText: 'Si, continuar',
68
+ cancelButtonText: "Cancelar"
69
+ }).then((result) => {
70
+ if (result) {
71
+ $scope.$evalAsync(function(){
72
+ ('#new-credit-card-modal').modal("show");
73
+ });
74
+ }
75
+ else{
76
+ self.create_subscription_after_new_card = false;
77
+ }
78
+ });
79
+ }
80
80
  })
81
81
  }
82
82
 
@@ -127,10 +127,6 @@
127
127
  $http.get("/easy_pay_u_latam/api/v1/pay_u_cards.json", {params: params}).then(
128
128
  function(res, status){
129
129
  self.cards = res.data.cards;
130
- //Si el usuario seleccinó un plan se crea la subscripción automaticamente
131
- if (self.create_subscription_after_new_card == true){
132
- self.CreateSubscription();
133
- }
134
130
  },
135
131
  function(res, status){
136
132
  }
@@ -165,7 +161,10 @@
165
161
  $("#new-credit-card-modal").modal("hide");
166
162
  swal("¡Excelente!", "¡La tarjeta de crédito creada con éxito!", "success");
167
163
 
168
-
164
+ //Si el usuario seleccinó un plan se crea la subscripción automaticamente
165
+ if (self.create_subscription_after_new_card == true){
166
+ self.CreateSubscription();
167
+ }
169
168
  },
170
169
  function(res, status){
171
170
  self.card_loading = false;
@@ -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.21'
2
+ VERSION = '0.1.28'
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.21
4
+ version: 0.1.28
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-17 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