easy_pay_u_latam 0.1.19 → 0.1.26

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: c4a4d762c11131172e32d443f38d3d2e4b01f6cfd159f81faa24dcd99381183e
4
- data.tar.gz: 724a6627b626555b646c4243ea63a01692c7861b2164285c69fa1f0443b9e718
3
+ metadata.gz: e0400eae8836ba7b7594aebab078c58d12d50f67226f4260f3d2c8b329a6d8d9
4
+ data.tar.gz: 1a4dd65dd66fc34d3bb1e2832f9917394fdc82b1b328ddaaa5706fdfad9a73bf
5
5
  SHA512:
6
- metadata.gz: 766db0c51dd2f553c1e2ec5b5103053e2d2ef849d8385622cc901cbc909c935d6d2e84622faadba0d50fe90e122149a1d666275bb03f2e0474fd4ac9379b75da
7
- data.tar.gz: 833a8a9d1434e86b7e80e6ce037d1af1c19222e5430e7528523adb8925e3f3ce1b53cb6e02abc0aedccfeaeebb5ec67930a8f2e52793de1dd155d80f7873a351
6
+ metadata.gz: fd3e4a6246d847bb4273d50193f654a4fef31ec0f1f57ba4f437f7889b6855e35ddc626727b5d3aa95ac06a2efecff2f786eff318378dbea717417c6b6b4f802
7
+ data.tar.gz: ad8e4a43b3eca88da922a82c2af20b58cd30dce19dfae069d00c48f46129155600471123abcb4fa2d9e4204fa377a84d65021ee5945b464bec7ee409afc3219c
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)
22
+ @payUConfig = EasyPayULatam.configuration
23
+
24
+ client = RApi::Client.new current_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)
66
+ @payUConfig = EasyPayULatam.configuration
67
+
68
+ client = RApi::Client.new current_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.19'
2
+ VERSION = '0.1.26'
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.19
4
+ version: 0.1.26
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-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -160,6 +160,7 @@ files:
160
160
  - app/assets/stylesheets/easy_pay_u_latam/styles.css
161
161
  - app/assets/stylesheets/easy_pay_u_latam/subscriptions/application.scss
162
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
163
164
  - app/controllers/easy_pay_u_latam/api/v1/pay_u_cards_controller.rb
164
165
  - app/controllers/easy_pay_u_latam/api/v1/pay_u_clients_controller.rb
165
166
  - app/controllers/easy_pay_u_latam/api/v1/pay_u_payments_controller.rb
@@ -198,6 +199,7 @@ files:
198
199
  - lib/easy_pay_u_latam/Configuration.rb
199
200
  - lib/easy_pay_u_latam/engine.rb
200
201
  - lib/easy_pay_u_latam/r_api.rb
202
+ - lib/easy_pay_u_latam/r_api/additional_charge.rb
201
203
  - lib/easy_pay_u_latam/r_api/card.rb
202
204
  - lib/easy_pay_u_latam/r_api/client.rb
203
205
  - lib/easy_pay_u_latam/r_api/invoice.rb