easy_pay_u_latam 0.1.18 → 0.1.23

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: 9a6cb82502e1d6b98cfeeccceaf51159d2c5b1cfc5f2d10ea72d5ed54d517189
4
- data.tar.gz: 320b6d1f0f2d2d6b2a482988deda882f2fbcb0ffb2f552ea43ce82e4f7d15421
3
+ metadata.gz: a7488eb02bd73a2e0a9e1985adeb73b08a077dc2fec24f84e8d1c6cefdc0f09f
4
+ data.tar.gz: 1037ea884d71536c6d3f1f589b1fd234aff545113b4321747d443d3560cf8441
5
5
  SHA512:
6
- metadata.gz: df76b6b63b16ad35af4a13b8bb78e43920f77ab061b3980e189fb069033987d0a9a7c1e2161bc63e41ef7243b79ec02d1bef165f282e8ffd7ca6bd89b57bc138
7
- data.tar.gz: b5cf62f61bbdbea169abfc1a86e4c48a7a1b968d42fe02dace8d0a91d458548e5ea189af4b4d7bdc8a2e2969e8af785c72858e84e54efcf9df08eb5060096134
6
+ metadata.gz: 690b7e42e7763aa14aa38a2cb8b19a5fdce8acccdc4f6e6c030527fc4ef42967ebb412743ea5ff9dc58d30ab04f3d2cdb52498b1918d71a16a97c38f9ecf8526
7
+ data.tar.gz: 66907a1086e3c0828a9e454349b1c64067d08f63b5acf841a737d5eb218e02d63f7493516daedb4cd7ba45c39ab81de1a68b1077d7162120c0820b076b4cabf4
data/README.md CHANGED
@@ -68,6 +68,15 @@ 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
71
80
  end
72
81
  ```
73
82
 
@@ -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
@@ -27,6 +26,8 @@ module EasyPayULatam
27
26
 
28
27
  if !current_user.last_payment.nil? && current_user.last_payment.end_date > Date.today
29
28
  subs.params["trialDays"] = (current_user.last_payment.end_date - Date.today).to_i
29
+ elsif current_user.last_payment.nil?
30
+ subs.params["trialDays"] = @plan.trial_days.blank? ? 0 : @plan.trial_days
30
31
  end
31
32
 
32
33
  subs.params["notifyUrl"] = "#{@payUConfig.get_root_url}/easy_pay_u_latam/api/v1/pay_u_payments/#{ @payu_payment.id}/confirmation.json?user_id=#{current_user.id}"
@@ -68,6 +69,7 @@ module EasyPayULatam
68
69
 
69
70
  def generate_payment(plan_code)
70
71
  plan = Plan.actives.find_by_payu_plan_code plan_code
72
+ @plan = plan
71
73
  # period_moths = 1 if plan.interval.downcase == "day"
72
74
  period_moths = 1 if plan.interval.downcase == "month"
73
75
  period_moths = 6 if plan.interval.downcase == "semester"
@@ -18,5 +18,47 @@ 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
+ addcharge
50
+ end
51
+
52
+ def remove_charge(id)
53
+ @payUConfig = EasyPayULatam.configuration
54
+
55
+ client = RApi::Client.new current_user.pay_u_costumer_id
56
+ addcharge = RApi::AdditionalCharge.new client, self.reference_recurring_payment
57
+
58
+ addcharge.delete id
59
+
60
+ addcharge
61
+ end
62
+
21
63
  end
22
64
  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
@@ -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/v4.9/subscriptions/#{@sub_id}/recurringBillItems}"
19
+ end
20
+
21
+ def url
22
+ @url = RApi.base_url + "/rest/v4.9/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
@@ -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.18'
2
+ VERSION = '0.1.23'
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.18
4
+ version: 0.1.23
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-05 00:00:00.000000000 Z
11
+ date: 2020-09-15 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