ishapi 0.1.8.246 → 0.1.8.248

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9ddbe9fcd8124677c56eefec990b277af917d78858eb4407c79afc1640b39898
4
- data.tar.gz: 9dec346d2bde34a2dae7256ba8b389e2432834c8424a42b996f4f0eb216d56f8
3
+ metadata.gz: c22c9af79d588c3398c93d419294e103fb1cf0a2832dc194767e5355875a3540
4
+ data.tar.gz: e478c4d3932697c2c8fa9f5626b87c4942ab5df270b74db7a1971031008af2b6
5
5
  SHA512:
6
- metadata.gz: bf1287a34c2f5f289d5770b8123c6a7fe65b3ebbc3eb71761926e3679a0dbbacd3dd1996226569e8c2f60d830703c2c951fbf1054214d69bda96d28f2dd27a29
7
- data.tar.gz: dc5d08229ed5792dd1ff6e5c1e3f6322605d2222ffe53a988db24a133ad5090065c803b0fe2bd1d3c2b45f9cfa5c95b8385c5c82241274c5b73f2abf7dd7ebd6
6
+ metadata.gz: 83d25afaa7f23d1ac7f1902d1112ed3b65f70848bca00e93ea98072fecabe889837472f1b2b97c37f2fa026e1c873409a0ef24ff90d4757f7adb2f8e2971e4b4
7
+ data.tar.gz: cb3f87379270bfd0ded5f35bdc7e12bdbc146b04361748221631bdb5269e4fd66f350d085d80b4827a188f51408dd0999dfd49aa09e9243b45e1f056360b1bec
@@ -1,132 +1,96 @@
1
1
  require_dependency "ishapi/application_controller"
2
- module Ishapi
3
- class PaymentsController < ApplicationController
4
-
5
- before_action :check_profile, only: %i| create2 unlock |
6
-
7
- # alphabetized : )
8
-
9
- ##
10
- ## this was for invoices on wasya.co
11
- ## 20200712
12
- ##
13
- def create
14
- authorize! :open_permission, ::Ishapi
15
- begin
16
- invoice = Ish::Invoice.where( :email => params[:email], :number => params[:number] ).first
17
- payment = Ish::Payment.new :invoice => invoice, :email => params[:email], :amount => params[:amount]
18
- amount_cents = ( params[:amount].to_f * 100 ).to_i
19
-
20
- ::Stripe.api_key = STRIPE_SK
21
- acct = Stripe::Account.create(
22
- :country => 'US',
23
- :type => 'custom'
24
- )
25
- charge = ::Stripe::Charge.create(
26
- :amount => amount_cents,
27
- :currency => 'usd',
28
- :source => params[:token][:id],
29
- :destination => {
30
- :account => acct,
31
- }
32
- )
33
-
34
- payment.charge = JSON.parse( charge.to_json )
35
- if payment.save
36
- render :json => { :status => :ok }
37
- else
38
- render :status => 404, :json => {}
39
- end
40
- rescue Mongoid::Errors::DocumentNotFound => e
41
- puts! e, 'e'
42
- render :status => 404, :json => {}
43
- end
2
+ class Ishapi::PaymentsController < ApplicationController
3
+
4
+ before_action :check_profile, only: %i| create2 unlock |
5
+
6
+ # alphabetized : )
7
+
8
+ ## _vp_ 2020-07-21 This is for guyd
9
+ ## _vp_ 2022-03-01 It's been a while!
10
+ ## _vp_ 2022-09-04 continue
11
+ ##
12
+ ## @TODO: cannot proceed if already is_purchasing?
13
+ ##
14
+ def create
15
+ authorize! :create, ::Ish::Payment
16
+ @current_profile.update_attributes({ is_purchasing: true })
17
+
18
+ begin
19
+ amount_cents = params[:amount_cents].to_i # @TODO: change
20
+
21
+ ::Stripe.api_key = ::STRIPE_SK
22
+ intent = Stripe::PaymentIntent.create({
23
+ amount: amount_cents,
24
+ currency: 'usd',
25
+ metadata: { integration_check: "accept_a_payment" },
26
+ })
27
+
28
+ payment = Ish::Payment.create!(
29
+ client_secret: intent.client_secret,
30
+ email: @current_profile.email,
31
+ payment_intent_id: intent.id,
32
+ profile_id: @current_profile.id,
33
+ )
34
+ render json: {
35
+ client_secret: intent.client_secret,
36
+ clientSecret: intent.client_secret,
37
+ }
38
+
39
+ rescue Mongoid::Errors::DocumentNotFound => e
40
+ puts! e, '#create2 Mongoid::Errors::DocumentNotFound'
41
+ render :status => 404, :json => e
44
42
  end
43
+ end
45
44
 
46
- ## _vp_ 2020-07-21 This is for guyd
47
- ## _vp_ 2022-03-01 It's been a while!
48
- ## _vp_ 2022-09-04 continue
49
- ##
50
- ## @TODO: cannot proceed if already is_purchasing?
51
- ##
52
- def create2
53
- authorize! :create, ::Ish::Payment
54
- @current_profile.update_attributes({ is_purchasing: true })
55
-
56
- begin
57
- amount_cents = params[:amount_cents].to_i # @TODO: change
58
-
59
- ::Stripe.api_key = ::STRIPE_SK
60
- intent = Stripe::PaymentIntent.create({
61
- amount: amount_cents,
62
- currency: 'usd',
63
- metadata: { integration_check: "accept_a_payment" },
64
- })
65
-
66
- payment = Ish::Payment.create!(
67
- client_secret: intent.client_secret,
68
- email: @current_profile.email,
69
- payment_intent_id: intent.id,
70
- profile_id: @current_profile.id,
71
- )
72
-
73
- render json: { client_secret: intent.client_secret }
74
- rescue Mongoid::Errors::DocumentNotFound => e
75
- puts! e, '#create2 Mongoid::Errors::DocumentNotFound'
76
- render :status => 404, :json => e
77
- end
45
+ ##
46
+ ## webhook
47
+ ##
48
+ def stripe_confirm
49
+ authorize! :open_permission, ::Ishapi
50
+ payload = request.body.read
51
+ event = nil
52
+ begin
53
+ event = Stripe::Event.construct_from(JSON.parse(payload, symbolize_names: true))
54
+ rescue StandardError => err
55
+ puts! err, 'could not #stripe_confirm'
56
+ render status: 400, json: { status: :not_ok }
57
+ return
78
58
  end
79
59
 
80
- ##
81
- ## webhook
82
- ##
83
- def stripe_confirm
84
- authorize! :open_permission, ::Ishapi
85
- payload = request.body.read
86
- event = nil
87
- begin
88
- event = Stripe::Event.construct_from(JSON.parse(payload, symbolize_names: true))
89
- rescue StandardError => e
90
- puts! e, 'could not #stripe_confirm'
91
- render status: 400, json: { status: :not_ok }
92
- return
93
- end
94
-
95
- payment_intent = event.data.object
96
-
97
- payment = Ish::Payment.where( payment_intent_id: payment_intent.id ).first
98
- if payment && payment_intent['status'] == 'succeeded'
99
-
100
- payment.update_attributes( status: :confirmed )
101
- n_unlocks = payment.profile.n_unlocks + 1 # @TODO: it's not always 5? adjust
102
-
103
- payment.profile.update_attributes!( n_unlocks: n_unlocks, is_purchasing: false )
104
- end
105
-
106
- render status: 200, json: { status: :ok }
107
- end
60
+ payment_intent = event.data.object
108
61
 
109
- ##
110
- ## Spend an unlock without spending money. _vp_ 2022-03-01
111
- ##
112
- def unlock
113
- authorize! :unlock, ::Ish::Payment
114
- item = Object::const_get(params['kind']).find params['id']
62
+ payment = Ish::Payment.where( payment_intent_id: payment_intent.id ).first
63
+ if payment && payment_intent['status'] == 'succeeded'
115
64
 
116
- existing = Purchase.where( user_profile: @current_profile, item: item ).first
117
- if existing
118
- render status: 200, json: { status: :ok, message: 'already purchased' }
119
- return
120
- end
65
+ payment.update_attributes( status: :confirmed )
66
+ n_unlocks = payment.profile.n_unlocks + 1 # @TODO: it's not always 5, adjust! herehere
121
67
 
122
- @current_profile.inc( n_unlocks: -item.premium_tier )
68
+ payment.profile.update_attributes!( n_unlocks: n_unlocks, is_purchasing: false )
69
+ end
123
70
 
124
- purchase = ::Gameui::PremiumPurchase.create!( item: item, user_profile: @current_profile, )
71
+ render status: 200, json: { status: :ok }
72
+ end
125
73
 
126
- @profile = @current_profile
127
- render 'ishapi/user_profiles/account'
74
+ ##
75
+ ## Spend an unlock without spending money. _vp_ 2022-03-01
76
+ ##
77
+ def unlock
78
+ authorize! :unlock, ::Ish::Payment
79
+ item = Object::const_get(params['kind']).find params['id']
80
+
81
+ existing = Purchase.where( user_profile: @current_profile, item: item ).first
82
+ if existing
83
+ render status: 200, json: { status: :ok, message: 'already purchased' }
84
+ return
128
85
  end
129
86
 
87
+ @current_profile.inc( n_unlocks: -item.premium_tier )
88
+
89
+ purchase = ::Gameui::PremiumPurchase.create!( item: item, user_profile: @current_profile, )
90
+
91
+ @profile = @current_profile
92
+ render 'ishapi/user_profiles/account'
130
93
  end
94
+
131
95
  end
132
96
 
@@ -1,17 +1,6 @@
1
1
 
2
- =begin
3
-
4
- m_id_2 = "2021-07-12T19_17_26Fpedidos_jmc2_gmail_com"
5
- stub = Stub.new( object_key: m_id_2 )
6
- stub = Stub.find_by( object_key: m_id_2 )
7
- stub.update_attribute(:state, 'state_pending')
8
- Ishapi::EmailMessageIntakeJob.perform_now( stub.id.to_s )
9
-
10
- =end
11
-
12
-
13
2
  ##
14
- ## 2023-02-26 _vp_ let's go
3
+ ## 2023-02-26 _vp_ Let's go
15
4
  ## 2023-03-02 _vp_ Continue
16
5
  ## 2023-03-07 _vp_ Continue
17
6
  ##
@@ -131,7 +120,7 @@ class Ishapi::EmailMessageIntakeJob < Ishapi::ApplicationJob
131
120
  @message.email_conversation_id = conv.id
132
121
  conv.update_attributes({
133
122
  state: Conv::STATE_UNREAD,
134
- latest_at: the_mail.date,
123
+ latest_at: the_mail.date || Time.now.to_datetime,
135
124
  wp_term_ids: ( [ email_inbox_tag_id ] + conv.wp_term_ids + stub.wp_term_ids ).uniq,
136
125
  })
137
126
 
data/config/routes.rb CHANGED
@@ -47,10 +47,8 @@ Ishapi::Engine.routes.draw do
47
47
 
48
48
  post 'do_purchase', to: 'gameui#do_purchase' # @TODO: rename to just purchase, or destroy endpoint
49
49
  post 'payments', :to => 'payments#create'
50
- post 'payments2', :to => 'payments#create2' # @TODO: change
51
- get 'payments2', to: 'payments#create2'
52
50
  post 'payments/unlock', to: 'payments#unlock' # do_purchase
53
- post 'stripe_confirm', to: 'payments#stripe_confirm' # @TODO: test-drive
51
+ post 'payments/stripe_confirm', to: 'payments#stripe_confirm' # @TODO: test-drive herehere
54
52
 
55
53
  get 'photos/view/:id', to: 'photos#show'
56
54
  get 'profiles/view/:username', :to => 'user_profiles#show'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ishapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8.246
4
+ version: 0.1.8.248
5
5
  platform: ruby
6
6
  authors:
7
7
  - piousbox
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-27 00:00:00.000000000 Z
11
+ date: 2023-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails