app_manager 2.7.1 → 2.8.0
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 +4 -4
- data/.cursor/rules/commit-and-pr.mdc +33 -0
- data/.github/copilot-instructions.md +25 -0
- data/CHANGELOG.md +97 -0
- data/CLAUDE.md +10 -0
- data/Gemfile.lock +72 -72
- data/README.md +51 -1
- data/app/controllers/app_manager/banners_controller.rb +1 -0
- data/app/controllers/app_manager/charges_controller.rb +38 -18
- data/app/controllers/app_manager/plans_controller.rb +47 -15
- data/app/controllers/concerns/app_manager/authenticate.rb +4 -2
- data/docs/commit-and-pr-standards.md +121 -0
- data/lib/app_manager/config.rb +9 -0
- data/lib/app_manager/graphql_helper.rb +22 -18
- data/lib/app_manager/model.rb +8 -8
- data/lib/app_manager/protection.rb +5 -4
- data/lib/app_manager/session_token.rb +121 -0
- data/lib/app_manager/shopify_api.rb +161 -0
- data/lib/app_manager/version.rb +1 -1
- data/lib/app_manager.rb +3 -0
- data/lib/generators/app_manager/install/templates/app_manager.rb.tt +3 -1
- metadata +9 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a1af077367723608dd6c4b9b917be9ce48dee6b5ccb01a468eef385a60c5375a
|
|
4
|
+
data.tar.gz: db446ea77cfbf40ec9e9891786e2a48446d6b74c33ee930c38822f99006d09b2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2a1d26b06d1f4d78b142d0943b04dcecd6347df4f6b43e650d8e712750b6de441fae90f2796792892a17c413da9ebd477757becff30413e8359fc33083031d2c
|
|
7
|
+
data.tar.gz: fbe2e3536bd1730d9fb0a7eb87fd85fd774c63f5d8e5cda505699b262ef653493b672122ddf8d17377b709368ce401af85009a7ab62b239dac02db3c30f64c17
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Commit and PR message standards for merges tracked in Atlas
|
|
3
|
+
alwaysApply: true
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
When you write a commit message, a PR title or a PR description in this repo,
|
|
7
|
+
follow these rules. Full version: `docs/commit-and-pr-standards.md`.
|
|
8
|
+
|
|
9
|
+
## PR title (with squash-merge it becomes the commit on main)
|
|
10
|
+
- Format: `<JIRA-KEY>: <what changed, in plain words>`, imperative mood, under ~72 characters.
|
|
11
|
+
- Say what changed for the user or the system, not which branch it came from.
|
|
12
|
+
- Never use a branch name (`staging-v2`, `develop`, `testing to main`), `WIP`, `fix`, `update` or `changes`.
|
|
13
|
+
- Release / promotion PRs (develop → main, staging → master, staging-v2 → master-v2):
|
|
14
|
+
`Release: <the two or three main things it carries>`
|
|
15
|
+
|
|
16
|
+
## PR description: always end it with this block
|
|
17
|
+
```
|
|
18
|
+
Change type: New Feature | Improvement | Bug Fix | Refactor | Security | Maintenance
|
|
19
|
+
Feature scope: Major | Minor
|
|
20
|
+
Short description: <one sentence a product manager would understand>
|
|
21
|
+
Notes: <optional>
|
|
22
|
+
```
|
|
23
|
+
- New Feature: new user-facing functionality. Improvement: an existing feature made better.
|
|
24
|
+
Bug Fix: a fix for a defect shipped earlier. Refactor: no behaviour change.
|
|
25
|
+
Security: security-motivated. Maintenance: dependencies, infra, CI, version bumps.
|
|
26
|
+
- Major = significant surface-area change (new tab, endpoint, migration, broad behaviour change).
|
|
27
|
+
Minor = small and contained. When in doubt, Minor.
|
|
28
|
+
- Several changes in one PR: repeat the block per change, each starting with `Task: <name>`.
|
|
29
|
+
|
|
30
|
+
## Also
|
|
31
|
+
- Never leave a PR template unfilled: fill it in, or delete it.
|
|
32
|
+
- Commit messages: one line saying what changed (`Handle error on charges`, not `fix`).
|
|
33
|
+
- Put the Jira key in the branch name or the commit.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
## Commit and PR messages
|
|
2
|
+
|
|
3
|
+
When you write a commit message, a PR title or a PR description in this repository,
|
|
4
|
+
follow these rules. The full version is in `docs/commit-and-pr-standards.md`.
|
|
5
|
+
|
|
6
|
+
**PR title** (with squash-merge it becomes the commit on main):
|
|
7
|
+
`<JIRA-KEY>: <what changed, in plain words>`. Use the imperative mood and keep it under
|
|
8
|
+
~72 characters. Never use a branch name (`staging-v2`, `develop`, `testing to main`),
|
|
9
|
+
`WIP`, `fix` or `update`. For release PRs (develop → main, staging-v2 → master-v2), use
|
|
10
|
+
`Release: <the two or three main things it carries>`.
|
|
11
|
+
|
|
12
|
+
**End every PR description with this block:**
|
|
13
|
+
```
|
|
14
|
+
Change type: New Feature | Improvement | Bug Fix | Refactor | Security | Maintenance
|
|
15
|
+
Feature scope: Major | Minor
|
|
16
|
+
Short description: <one sentence a product manager would understand>
|
|
17
|
+
Notes: <optional>
|
|
18
|
+
```
|
|
19
|
+
- Major = significant surface-area change. Minor = small and contained. When in doubt, Minor.
|
|
20
|
+
- If the PR contains several changes, repeat the block for each, starting it with `Task: <name>`.
|
|
21
|
+
|
|
22
|
+
**Also:**
|
|
23
|
+
- Never leave a PR template unfilled.
|
|
24
|
+
- Commit messages are one line saying what changed.
|
|
25
|
+
- Put the Jira key in the branch name or the commit.
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to the `app_manager` gem are documented here, newest first.
|
|
4
|
+
Versions before 2.3.5 are not listed. 2.6.x was never released.
|
|
5
|
+
|
|
6
|
+
## 2.8.0 - 2026-11-18
|
|
7
|
+
|
|
8
|
+
Support for Shopify's expiring offline access tokens (required for public apps
|
|
9
|
+
from 1 January 2027). Backward compatible: an app that changes nothing keeps the
|
|
10
|
+
previous behaviour.
|
|
11
|
+
|
|
12
|
+
- Billing calls now get their token from an app-supplied resolver instead of
|
|
13
|
+
reading the token column directly, so a merchant no longer gets a dead token
|
|
14
|
+
(HTTP 401) when upgrading a plan.
|
|
15
|
+
- New `config.shopify_token_resolver`: any object, class or class name responding
|
|
16
|
+
to `token(shop_domain)` and `refresh(shop_domain)`. Unset, the default
|
|
17
|
+
`AppManager::ColumnTokenResolver` reads the token exactly as before.
|
|
18
|
+
- New `AppManager::ModelTokenResolver` for shop models with a
|
|
19
|
+
`fresh_shopify_token` instance method. After a rejection it calls the method
|
|
20
|
+
again (with `force: true` if it accepts that keyword). Falls back to
|
|
21
|
+
`shop.shopify_token` when the method is missing, blank or raises.
|
|
22
|
+
- The token is read through the model's accessor, not the raw attribute, so an
|
|
23
|
+
encrypted `shopify_token` column comes back decrypted.
|
|
24
|
+
- Every gem call to Shopify (create, confirm, cancel and query charges) goes
|
|
25
|
+
through `AppManager::ShopifyApi`. A 401, or a 403 saying `Non-expiring access
|
|
26
|
+
tokens are no longer accepted`, triggers exactly one retry, and only with a
|
|
27
|
+
token different from the rejected one. A 403 for a missing scope is not a
|
|
28
|
+
rejection.
|
|
29
|
+
- `GraphqlHelper.new` no longer needs the token (a second argument is still
|
|
30
|
+
accepted as a fallback). The missing-token log no longer includes the token.
|
|
31
|
+
|
|
32
|
+
## 2.7.2 - 2026-11-03
|
|
33
|
+
|
|
34
|
+
- Security: `/api/app-manager` routes now require authentication: the App
|
|
35
|
+
Manager `token` header, or a verified Shopify session token for the routes the
|
|
36
|
+
billing page calls. New `shopify_api_secret` config.
|
|
37
|
+
- Security: a merchant can no longer get a paid plan without paying; the charge
|
|
38
|
+
callback only changes the plan for an `active` Shopify charge.
|
|
39
|
+
|
|
40
|
+
## 2.7.1 - 2026-07-24
|
|
41
|
+
|
|
42
|
+
- A free custom plan is marked as used when a shop changes to it.
|
|
43
|
+
|
|
44
|
+
## 2.7.0 - 2026-07-23
|
|
45
|
+
|
|
46
|
+
- The discount applied to a charge (value, type, duration, source) is stored on
|
|
47
|
+
the charge. Custom plans can be used once.
|
|
48
|
+
|
|
49
|
+
## 2.5.0 - 2026-05-29
|
|
50
|
+
|
|
51
|
+
- New plan fields (trial days text, most popular badge) and an FAQs table. Run
|
|
52
|
+
`rails g app_manager:install` and migrate. New `most_popular_plan_ids` config.
|
|
53
|
+
|
|
54
|
+
## 2.4.11 - 2026-05-14
|
|
55
|
+
|
|
56
|
+
- Safer install generator: migrations are skipped when already applied.
|
|
57
|
+
|
|
58
|
+
## 2.4.10 - 2026-05-13
|
|
59
|
+
|
|
60
|
+
- Added a `details` column to plans.
|
|
61
|
+
|
|
62
|
+
## 2.4.9 - 2026-05-08
|
|
63
|
+
|
|
64
|
+
- The highlights and note columns are only used when they exist, for backward
|
|
65
|
+
compatibility.
|
|
66
|
+
|
|
67
|
+
## 2.4.8 - 2026-05-08
|
|
68
|
+
|
|
69
|
+
- Added `note` and `highlights` columns to plans.
|
|
70
|
+
|
|
71
|
+
## 2.4.7 - 2026-05-01
|
|
72
|
+
|
|
73
|
+
- Fixed the SDK version parameter sent to App Manager.
|
|
74
|
+
|
|
75
|
+
## 2.4.6 - 2026-05-01
|
|
76
|
+
|
|
77
|
+
- The SDK version is sent to App Manager.
|
|
78
|
+
|
|
79
|
+
## 2.4.5 - 2026-03-19
|
|
80
|
+
|
|
81
|
+
- Security: `shopify_token` is excluded from the users response.
|
|
82
|
+
|
|
83
|
+
## 2.4.4 - 2026-03-18
|
|
84
|
+
|
|
85
|
+
- Security: fixed remote code execution and SQL injection vulnerabilities.
|
|
86
|
+
|
|
87
|
+
## 2.4.0 - 2.4.3 - 2026-02-26 to 2026-03-02
|
|
88
|
+
|
|
89
|
+
- Fail-safe: incremental plan updates.
|
|
90
|
+
|
|
91
|
+
## 2.3.7 - 2026-02-18
|
|
92
|
+
|
|
93
|
+
- Rails 7 `allow_other_host` support for redirects.
|
|
94
|
+
|
|
95
|
+
## 2.3.6 - 2025-10-28
|
|
96
|
+
|
|
97
|
+
- Support for the development-store partner field.
|
data/CLAUDE.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
## Commit and PR messages
|
|
2
|
+
|
|
3
|
+
When you write a commit message, a PR title or a PR description, follow the rules in
|
|
4
|
+
@docs/commit-and-pr-standards.md.
|
|
5
|
+
|
|
6
|
+
Short version:
|
|
7
|
+
- PR title: `<JIRA-KEY>: <what changed>`. Never a branch name, `WIP` or `fix`.
|
|
8
|
+
- Release PRs: `Release: <the main things it carries>`.
|
|
9
|
+
- End every PR description with `Change type:`, `Feature scope:` and `Short description:` lines.
|
|
10
|
+
- Never leave a PR template unfilled.
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
app_manager (2.
|
|
4
|
+
app_manager (2.8.0)
|
|
5
5
|
activerecord-import (~> 1.4)
|
|
6
6
|
httparty
|
|
7
7
|
kaminari (>= 0.16.3)
|
|
@@ -12,29 +12,29 @@ GEM
|
|
|
12
12
|
specs:
|
|
13
13
|
action_text-trix (2.1.19)
|
|
14
14
|
railties
|
|
15
|
-
actioncable (8.1.
|
|
16
|
-
actionpack (= 8.1.
|
|
17
|
-
activesupport (= 8.1.
|
|
15
|
+
actioncable (8.1.4.1)
|
|
16
|
+
actionpack (= 8.1.4.1)
|
|
17
|
+
activesupport (= 8.1.4.1)
|
|
18
18
|
nio4r (~> 2.0)
|
|
19
19
|
websocket-driver (>= 0.6.1)
|
|
20
20
|
zeitwerk (~> 2.6)
|
|
21
|
-
actionmailbox (8.1.
|
|
22
|
-
actionpack (= 8.1.
|
|
23
|
-
activejob (= 8.1.
|
|
24
|
-
activerecord (= 8.1.
|
|
25
|
-
activestorage (= 8.1.
|
|
26
|
-
activesupport (= 8.1.
|
|
21
|
+
actionmailbox (8.1.4.1)
|
|
22
|
+
actionpack (= 8.1.4.1)
|
|
23
|
+
activejob (= 8.1.4.1)
|
|
24
|
+
activerecord (= 8.1.4.1)
|
|
25
|
+
activestorage (= 8.1.4.1)
|
|
26
|
+
activesupport (= 8.1.4.1)
|
|
27
27
|
mail (>= 2.8.0)
|
|
28
|
-
actionmailer (8.1.
|
|
29
|
-
actionpack (= 8.1.
|
|
30
|
-
actionview (= 8.1.
|
|
31
|
-
activejob (= 8.1.
|
|
32
|
-
activesupport (= 8.1.
|
|
28
|
+
actionmailer (8.1.4.1)
|
|
29
|
+
actionpack (= 8.1.4.1)
|
|
30
|
+
actionview (= 8.1.4.1)
|
|
31
|
+
activejob (= 8.1.4.1)
|
|
32
|
+
activesupport (= 8.1.4.1)
|
|
33
33
|
mail (>= 2.8.0)
|
|
34
34
|
rails-dom-testing (~> 2.2)
|
|
35
|
-
actionpack (8.1.
|
|
36
|
-
actionview (= 8.1.
|
|
37
|
-
activesupport (= 8.1.
|
|
35
|
+
actionpack (8.1.4.1)
|
|
36
|
+
actionview (= 8.1.4.1)
|
|
37
|
+
activesupport (= 8.1.4.1)
|
|
38
38
|
nokogiri (>= 1.8.5)
|
|
39
39
|
rack (>= 2.2.4)
|
|
40
40
|
rack-session (>= 1.0.1)
|
|
@@ -42,38 +42,38 @@ GEM
|
|
|
42
42
|
rails-dom-testing (~> 2.2)
|
|
43
43
|
rails-html-sanitizer (~> 1.6)
|
|
44
44
|
useragent (~> 0.16)
|
|
45
|
-
actiontext (8.1.
|
|
45
|
+
actiontext (8.1.4.1)
|
|
46
46
|
action_text-trix (~> 2.1.15)
|
|
47
|
-
actionpack (= 8.1.
|
|
48
|
-
activerecord (= 8.1.
|
|
49
|
-
activestorage (= 8.1.
|
|
50
|
-
activesupport (= 8.1.
|
|
47
|
+
actionpack (= 8.1.4.1)
|
|
48
|
+
activerecord (= 8.1.4.1)
|
|
49
|
+
activestorage (= 8.1.4.1)
|
|
50
|
+
activesupport (= 8.1.4.1)
|
|
51
51
|
globalid (>= 0.6.0)
|
|
52
52
|
nokogiri (>= 1.8.5)
|
|
53
|
-
actionview (8.1.
|
|
54
|
-
activesupport (= 8.1.
|
|
53
|
+
actionview (8.1.4.1)
|
|
54
|
+
activesupport (= 8.1.4.1)
|
|
55
55
|
builder (~> 3.1)
|
|
56
56
|
erubi (~> 1.11)
|
|
57
57
|
rails-dom-testing (~> 2.2)
|
|
58
|
-
rails-html-sanitizer (~> 1.6)
|
|
59
|
-
activejob (8.1.
|
|
60
|
-
activesupport (= 8.1.
|
|
58
|
+
rails-html-sanitizer (~> 1.6, >= 1.7.2)
|
|
59
|
+
activejob (8.1.4.1)
|
|
60
|
+
activesupport (= 8.1.4.1)
|
|
61
61
|
globalid (>= 0.3.6)
|
|
62
|
-
activemodel (8.1.
|
|
63
|
-
activesupport (= 8.1.
|
|
64
|
-
activerecord (8.1.
|
|
65
|
-
activemodel (= 8.1.
|
|
66
|
-
activesupport (= 8.1.
|
|
62
|
+
activemodel (8.1.4.1)
|
|
63
|
+
activesupport (= 8.1.4.1)
|
|
64
|
+
activerecord (8.1.4.1)
|
|
65
|
+
activemodel (= 8.1.4.1)
|
|
66
|
+
activesupport (= 8.1.4.1)
|
|
67
67
|
timeout (>= 0.4.0)
|
|
68
68
|
activerecord-import (1.8.1)
|
|
69
69
|
activerecord (>= 4.2)
|
|
70
|
-
activestorage (8.1.
|
|
71
|
-
actionpack (= 8.1.
|
|
72
|
-
activejob (= 8.1.
|
|
73
|
-
activerecord (= 8.1.
|
|
74
|
-
activesupport (= 8.1.
|
|
70
|
+
activestorage (8.1.4.1)
|
|
71
|
+
actionpack (= 8.1.4.1)
|
|
72
|
+
activejob (= 8.1.4.1)
|
|
73
|
+
activerecord (= 8.1.4.1)
|
|
74
|
+
activesupport (= 8.1.4.1)
|
|
75
75
|
marcel (~> 1.0)
|
|
76
|
-
activesupport (8.1.
|
|
76
|
+
activesupport (8.1.4.1)
|
|
77
77
|
base64
|
|
78
78
|
bigdecimal
|
|
79
79
|
concurrent-ruby (~> 1.0, >= 1.3.1)
|
|
@@ -86,7 +86,7 @@ GEM
|
|
|
86
86
|
securerandom (>= 0.3)
|
|
87
87
|
tzinfo (~> 2.0, >= 2.0.5)
|
|
88
88
|
uri (>= 0.13.1)
|
|
89
|
-
addressable (2.
|
|
89
|
+
addressable (2.9.2)
|
|
90
90
|
public_suffix (>= 2.0.2, < 8.0)
|
|
91
91
|
base64 (0.3.0)
|
|
92
92
|
bigdecimal (4.0.1)
|
|
@@ -97,13 +97,13 @@ GEM
|
|
|
97
97
|
crack (1.0.1)
|
|
98
98
|
bigdecimal
|
|
99
99
|
rexml
|
|
100
|
-
crass (1.0.
|
|
100
|
+
crass (1.0.8)
|
|
101
101
|
csv (3.3.5)
|
|
102
102
|
date (3.5.1)
|
|
103
103
|
diff-lcs (1.6.2)
|
|
104
104
|
dotenv (2.1.2)
|
|
105
105
|
drb (2.2.3)
|
|
106
|
-
erb (6.0.
|
|
106
|
+
erb (6.0.7)
|
|
107
107
|
erubi (1.13.1)
|
|
108
108
|
globalid (1.4.0)
|
|
109
109
|
activesupport (>= 6.1)
|
|
@@ -120,7 +120,7 @@ GEM
|
|
|
120
120
|
prism (>= 1.3.0)
|
|
121
121
|
rdoc (>= 4.0.0)
|
|
122
122
|
reline (>= 0.4.2)
|
|
123
|
-
json (2.21.
|
|
123
|
+
json (2.21.2)
|
|
124
124
|
kaminari (1.2.2)
|
|
125
125
|
activesupport (>= 4.1.0)
|
|
126
126
|
kaminari-actionview (= 1.2.2)
|
|
@@ -134,9 +134,9 @@ GEM
|
|
|
134
134
|
kaminari-core (= 1.2.2)
|
|
135
135
|
kaminari-core (1.2.2)
|
|
136
136
|
logger (1.7.0)
|
|
137
|
-
loofah (2.25.
|
|
137
|
+
loofah (2.25.3)
|
|
138
138
|
crass (~> 1.0.2)
|
|
139
|
-
nokogiri (>= 1.
|
|
139
|
+
nokogiri (>= 1.19.5)
|
|
140
140
|
mail (2.9.1)
|
|
141
141
|
logger
|
|
142
142
|
mini_mime (>= 0.1.1)
|
|
@@ -152,20 +152,20 @@ GEM
|
|
|
152
152
|
prism (~> 1.5)
|
|
153
153
|
multi_xml (0.9.1)
|
|
154
154
|
bigdecimal (>= 3.1, < 5)
|
|
155
|
-
net-imap (0.6.
|
|
155
|
+
net-imap (0.6.7)
|
|
156
156
|
date
|
|
157
157
|
net-protocol
|
|
158
158
|
net-pop (0.1.2)
|
|
159
159
|
net-protocol
|
|
160
|
-
net-protocol (0.
|
|
160
|
+
net-protocol (0.4.0)
|
|
161
161
|
timeout
|
|
162
|
-
net-smtp (0.5.
|
|
162
|
+
net-smtp (0.5.2)
|
|
163
163
|
net-protocol
|
|
164
164
|
nio4r (2.7.5)
|
|
165
|
-
nokogiri (1.19.
|
|
165
|
+
nokogiri (1.19.7)
|
|
166
166
|
mini_portile2 (~> 2.8.2)
|
|
167
167
|
racc (~> 1.4)
|
|
168
|
-
nokogiri (1.19.
|
|
168
|
+
nokogiri (1.19.7-x86_64-linux-gnu)
|
|
169
169
|
racc (~> 1.4)
|
|
170
170
|
pp (0.6.4)
|
|
171
171
|
prettyprint
|
|
@@ -177,7 +177,7 @@ GEM
|
|
|
177
177
|
reline (>= 0.6.0)
|
|
178
178
|
public_suffix (7.0.2)
|
|
179
179
|
racc (1.8.1)
|
|
180
|
-
rack (3.2.
|
|
180
|
+
rack (3.2.8)
|
|
181
181
|
rack-session (2.1.2)
|
|
182
182
|
base64 (>= 0.1.0)
|
|
183
183
|
rack (>= 3.0.0)
|
|
@@ -185,30 +185,30 @@ GEM
|
|
|
185
185
|
rack (>= 1.3)
|
|
186
186
|
rackup (2.3.1)
|
|
187
187
|
rack (>= 3)
|
|
188
|
-
rails (8.1.
|
|
189
|
-
actioncable (= 8.1.
|
|
190
|
-
actionmailbox (= 8.1.
|
|
191
|
-
actionmailer (= 8.1.
|
|
192
|
-
actionpack (= 8.1.
|
|
193
|
-
actiontext (= 8.1.
|
|
194
|
-
actionview (= 8.1.
|
|
195
|
-
activejob (= 8.1.
|
|
196
|
-
activemodel (= 8.1.
|
|
197
|
-
activerecord (= 8.1.
|
|
198
|
-
activestorage (= 8.1.
|
|
199
|
-
activesupport (= 8.1.
|
|
188
|
+
rails (8.1.4.1)
|
|
189
|
+
actioncable (= 8.1.4.1)
|
|
190
|
+
actionmailbox (= 8.1.4.1)
|
|
191
|
+
actionmailer (= 8.1.4.1)
|
|
192
|
+
actionpack (= 8.1.4.1)
|
|
193
|
+
actiontext (= 8.1.4.1)
|
|
194
|
+
actionview (= 8.1.4.1)
|
|
195
|
+
activejob (= 8.1.4.1)
|
|
196
|
+
activemodel (= 8.1.4.1)
|
|
197
|
+
activerecord (= 8.1.4.1)
|
|
198
|
+
activestorage (= 8.1.4.1)
|
|
199
|
+
activesupport (= 8.1.4.1)
|
|
200
200
|
bundler (>= 1.15.0)
|
|
201
|
-
railties (= 8.1.
|
|
201
|
+
railties (= 8.1.4.1)
|
|
202
202
|
rails-dom-testing (2.3.0)
|
|
203
203
|
activesupport (>= 5.0.0)
|
|
204
204
|
minitest
|
|
205
205
|
nokogiri (>= 1.6)
|
|
206
|
-
rails-html-sanitizer (1.7.
|
|
207
|
-
loofah (~> 2.25, >= 2.25.
|
|
206
|
+
rails-html-sanitizer (1.7.2)
|
|
207
|
+
loofah (~> 2.25, >= 2.25.3)
|
|
208
208
|
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
|
|
209
|
-
railties (8.1.
|
|
210
|
-
actionpack (= 8.1.
|
|
211
|
-
activesupport (= 8.1.
|
|
209
|
+
railties (8.1.4.1)
|
|
210
|
+
actionpack (= 8.1.4.1)
|
|
211
|
+
activesupport (= 8.1.4.1)
|
|
212
212
|
irb (~> 1.13)
|
|
213
213
|
rackup (>= 1.0.0)
|
|
214
214
|
rake (>= 12.2)
|
|
@@ -216,11 +216,11 @@ GEM
|
|
|
216
216
|
tsort (>= 0.2)
|
|
217
217
|
zeitwerk (~> 2.6)
|
|
218
218
|
rake (13.3.1)
|
|
219
|
-
rbs (4.0
|
|
219
|
+
rbs (4.2.0)
|
|
220
220
|
logger
|
|
221
221
|
prism (>= 1.6.0)
|
|
222
222
|
tsort
|
|
223
|
-
rdoc (8.
|
|
223
|
+
rdoc (8.1.0)
|
|
224
224
|
erb
|
|
225
225
|
prism (>= 1.6.0)
|
|
226
226
|
rbs (>= 4.0.0)
|
|
@@ -259,7 +259,7 @@ GEM
|
|
|
259
259
|
base64
|
|
260
260
|
websocket-extensions (>= 0.1.0)
|
|
261
261
|
websocket-extensions (0.1.5)
|
|
262
|
-
zeitwerk (2.8.
|
|
262
|
+
zeitwerk (2.8.3)
|
|
263
263
|
|
|
264
264
|
PLATFORMS
|
|
265
265
|
ruby
|
data/README.md
CHANGED
|
@@ -50,7 +50,8 @@ AppManager.configure do |config|
|
|
|
50
50
|
config.enable_caching = false # Optional, True to enable app-manager api response caching, default is enabled from gem
|
|
51
51
|
config.expires_in = 1.days # Optional, Example: 30.seconds, 5.minutes or 2.days Default caching is for 1.days from gem
|
|
52
52
|
config.app_url = '' # App URL like https://volumediscount.hulkapps.dev/ or #https://5044-2409-4052-209a-69da-9d7-925a-9418-a9c3.ngrok.io
|
|
53
|
-
config.shopify_api_key = '' # Shopify api key of app
|
|
53
|
+
config.shopify_api_key = '' # Required, Shopify api key of app
|
|
54
|
+
config.shopify_api_secret = ENV['SHOPIFY_API_SECRET'] # Required, Shopify api secret of app. Verifies the billing page's session tokens; use your own env name if it differs
|
|
54
55
|
config.shopify_api_version = '' # Must be 2022-04 or latest
|
|
55
56
|
config.shopify_table_name = 'shops' # Table name which is generated by shopify mostly it is 'shops'
|
|
56
57
|
config.shopify_domain_field = 'shopify_domain' #shopify domain field
|
|
@@ -137,6 +138,18 @@ end
|
|
|
137
138
|
APP_MANAGER_API_URL: 'https://XXXXXXXX.com'
|
|
138
139
|
```
|
|
139
140
|
|
|
141
|
+
* **Required: `config.shopify_api_key` and `config.shopify_api_secret`.** The `/api/app-manager/*` routes are authenticated:
|
|
142
|
+
|
|
143
|
+
| Routes | Caller | Required |
|
|
144
|
+
|---|---|---|
|
|
145
|
+
| `users`, `burst-cache`, `fail-safe-backup`, `fail-safe-backup-full`, `cancel-charge`, `plan/activate-global`, `plan/cancel-global` | App Manager | `token` header = `APP_MANAGER_ACCESS_TOKEN` (App Manager already sends it) |
|
|
146
|
+
| `plans`, `plan-features`, `marketing-banners`, `plan/process/:plan_id`, `active-without-plan` | Embedded billing page | Shopify session token in `Authorization: Bearer …`, verified with `shopify_api_key` and `shopify_api_secret` |
|
|
147
|
+
| `plan/callback` | Shopify's redirect after charge approval | — |
|
|
148
|
+
|
|
149
|
+
Point both settings at the env variables that hold your app's Shopify API key and secret, using your own names if they differ, for example `ENV['SHOPIFY_PRIVATE_KEY']`. A `shop` / `shop_domain` param that doesn't match the session token's shop gets a 403. Nothing throws if a setting is missing or wrong: every billing-page request returns 401. A missing secret is reported to your error tracker, and a wrong secret or key logs a warning; each message starts with `App Manager:`.
|
|
150
|
+
|
|
151
|
+
The billing page must send the session token: `@shopcircle/app-manager-web-components` 1.4.0+ does this through App Bridge. A frontend calling these routes with axios needs a request interceptor that adds `Authorization: Bearer ${await shopify.idToken()}`.
|
|
152
|
+
|
|
140
153
|
* App Manager provides a rake task that must needs to include in your existing app cron for every 10 minutes. Like if you are using [whenever](https://github.com/javan/whenever) gem then you MUST need to include following rake take in your 'schedule.rb' (created by whenever gem)
|
|
141
154
|
|
|
142
155
|
```
|
|
@@ -250,6 +263,43 @@ rails db:migrate
|
|
|
250
263
|
```
|
|
251
264
|
|
|
252
265
|
|
|
266
|
+
### Shopify expiring offline access tokens
|
|
267
|
+
|
|
268
|
+
Shopify requires public apps to use **expiring offline access tokens** from
|
|
269
|
+
1 January 2027. They live 60 minutes, so a token read straight from the database
|
|
270
|
+
can already be dead. The gem no longer needs to read it: it asks your app for a
|
|
271
|
+
token and, if Shopify rejects it, asks again for a replacement.
|
|
272
|
+
|
|
273
|
+
**Apps still on non-expiring tokens need do nothing** - unset, the gem reads the
|
|
274
|
+
`field_names['shopify_token']` attribute through the shop model, as before.
|
|
275
|
+
|
|
276
|
+
**Shop model with `fresh_shopify_token`.** If your shop model has an instance
|
|
277
|
+
method `fresh_shopify_token` that returns a live token (renewing it if needed):
|
|
278
|
+
|
|
279
|
+
```ruby
|
|
280
|
+
AppManager.configure do |config|
|
|
281
|
+
config.shopify_token_resolver = AppManager::ModelTokenResolver
|
|
282
|
+
end
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
The gem calls `shop.fresh_shopify_token`. After Shopify rejects a token it calls it
|
|
286
|
+
again (with `force: true` if the method accepts a `force:` keyword) and replays the
|
|
287
|
+
request once, only if the result differs from the rejected token. If the model has no
|
|
288
|
+
such method, `shop.shopify_token` is read (through the model's accessor, so an encrypted column comes back decrypted), so the setting is safe before you migrate.
|
|
289
|
+
|
|
290
|
+
**Anything else.** Provide any object, class or class name responding to:
|
|
291
|
+
|
|
292
|
+
```ruby
|
|
293
|
+
class MyTokenResolver
|
|
294
|
+
def token(shop_domain); end # a token valid right now, or nil
|
|
295
|
+
def refresh(shop_domain); end # a replacement after a rejection, or nil
|
|
296
|
+
end
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
A 401, or a 403 saying `Non-expiring access tokens are no longer accepted`, counts as
|
|
300
|
+
a rejection. A 403 for a missing scope does not. Both methods run in web requests and
|
|
301
|
+
background jobs, so they must be safe to call concurrently for one shop.
|
|
302
|
+
|
|
253
303
|
<a name="step5"></a>
|
|
254
304
|
### Extras
|
|
255
305
|
|
|
@@ -2,6 +2,7 @@ require_dependency "app_manager/application_controller"
|
|
|
2
2
|
|
|
3
3
|
module AppManager
|
|
4
4
|
class BannersController < ApplicationController
|
|
5
|
+
prepend_before_action :authorize_session_or_api_token, :only => [:marketing_banner]
|
|
5
6
|
cache_response_for :marketing_banner
|
|
6
7
|
def marketing_banner
|
|
7
8
|
begin
|
|
@@ -2,6 +2,9 @@ require_dependency "app_manager/application_controller"
|
|
|
2
2
|
module AppManager
|
|
3
3
|
class ChargesController < ApplicationController
|
|
4
4
|
include HTTParty
|
|
5
|
+
prepend_before_action :authorize_request, :only => [:cancel_charge, :activate_global, :cancel_global]
|
|
6
|
+
# callback stays open: Shopify redirects the merchant there after approving a charge.
|
|
7
|
+
prepend_before_action :authorize_session_or_api_token, :only => [:process_plan]
|
|
5
8
|
skip_before_action :verify_authenticity_token, :only => [:process_plan,:activate_global,:cancel_charge,:cancel_global]
|
|
6
9
|
before_action :params_permit
|
|
7
10
|
require 'time'
|
|
@@ -20,7 +23,7 @@ module AppManager
|
|
|
20
23
|
active_charge_data = plan_obj.get_charge(params[:shop])
|
|
21
24
|
begin
|
|
22
25
|
if active_charge_data && active_charge_data.any? && !active_charge_data['active_charge'].nil? && !active_charge_data['active_charge']['charge_id'].nil?
|
|
23
|
-
gq_obj = AppManager::GraphqlHelper.new(@shop.shopify_domain
|
|
26
|
+
gq_obj = AppManager::GraphqlHelper.new(@shop.shopify_domain)
|
|
24
27
|
rec_cancel_data = gq_obj.recurring_charge_cancel_api_call(active_charge_data['active_charge']['charge_id'], @shop)
|
|
25
28
|
if !rec_cancel_data["errors"].present? && (rec_cancel_data["data"].present? && rec_cancel_data["data"]["appSubscriptionCancel"].present? && !rec_cancel_data["data"]["appSubscriptionCancel"]["userErrors"].any? && (rec_cancel_data["data"]["appSubscriptionCancel"]["appSubscription"]["status"] == 'CANCELLED'))
|
|
26
29
|
# cancelled_charge_id = rec_cancel_data["data"]["appSubscriptionCancel"]["appSubscription"]["id"].split('/')[-1]
|
|
@@ -71,7 +74,7 @@ module AppManager
|
|
|
71
74
|
request_data.merge!('old_plan' => params['old_plan']) if params['old_plan'].present?
|
|
72
75
|
|
|
73
76
|
return_url = "#{app_url}#{plan_callback_path}?#{Rack::Utils.build_query(request_data)}"
|
|
74
|
-
gq_obj = AppManager::GraphqlHelper.new(@shop.shopify_domain
|
|
77
|
+
gq_obj = AppManager::GraphqlHelper.new(@shop.shopify_domain)
|
|
75
78
|
discount_local_storage = params[:discount_code].present? && !params[:discount_code].nil? ? params[:discount_code] : nil
|
|
76
79
|
data = gq_obj.recurring_charge_api_call(plan_data, return_url, @shop,discount_local_storage)
|
|
77
80
|
# Stash the discount snapshot so the callback can persist it on the charge row.
|
|
@@ -103,32 +106,41 @@ module AppManager
|
|
|
103
106
|
def callback
|
|
104
107
|
if params[:charge_id].present? && params[:shop].present? && params[:plan].present?
|
|
105
108
|
@shop = shop_data
|
|
106
|
-
shopify_token = @field_names['shopify_token']
|
|
107
109
|
shopify_domain = @field_names['name']
|
|
108
110
|
grandfathered_field = @field_names['grandfathered']
|
|
109
111
|
discounted_plans = []
|
|
110
112
|
if !@shop.nil?
|
|
111
113
|
old_plan_id = @shop[@plan_field]
|
|
112
114
|
old_plan_data = nil
|
|
113
|
-
|
|
114
|
-
charges =
|
|
115
|
+
raise Error, "Invalid charge" unless params[:charge_id].to_s.match?(/\A\d+\z/)
|
|
116
|
+
charges = AppManager::ShopifyApi.rest(@shop[shopify_domain], :get, "recurring_application_charges/#{params[:charge_id]}.json")
|
|
117
|
+
charges_body = (JSON.parse(charges.body.to_s) rescue nil)
|
|
115
118
|
|
|
116
|
-
if
|
|
119
|
+
if charges_body && charges_body.is_a?(Hash) && charges_body.has_key?('recurring_application_charge')
|
|
120
|
+
|
|
121
|
+
charge = charges_body['recurring_application_charge']
|
|
122
|
+
return redirect_to_app if charge['status'].to_s.downcase != 'active'
|
|
123
|
+
|
|
124
|
+
# Read the plan from Shopify's stored return_url: the query string can be edited.
|
|
125
|
+
bound = Rack::Utils.parse_query(URI.parse(charge['return_url'].to_s).query.to_s) rescue {}
|
|
126
|
+
raise Error, "Invalid charge" if bound['plan'].blank? || bound['shop'] != params[:shop]
|
|
127
|
+
plan_id = bound['plan']
|
|
128
|
+
discount_id = bound['discount']
|
|
117
129
|
|
|
118
130
|
plan_obj = AppManager::Client.new
|
|
119
|
-
|
|
131
|
+
# TODO: an empty plan or failed store_charge leaves a paying merchant without the plan; report and retry.
|
|
132
|
+
plan_data = plan_obj.get_plan(plan_id, params[:shop])
|
|
120
133
|
|
|
121
|
-
charge = charges.parsed_response['recurring_application_charge']
|
|
122
134
|
charge['charge_id'] = charge['id']
|
|
123
135
|
charge['type'] = 'recurring'
|
|
124
|
-
charge['plan_id'] =
|
|
136
|
+
charge['plan_id'] = plan_id
|
|
125
137
|
charge['shop_domain'] = params[:shop]
|
|
126
138
|
charge['interval'] = plan_data['interval']['value']
|
|
127
139
|
|
|
128
140
|
['api_client_id', 'return_url', 'decorated_return_url','id','id','currency'].each { |k| charge.delete k }
|
|
129
141
|
|
|
130
142
|
# Merge the discount snapshot captured at charge creation onto the charge row.
|
|
131
|
-
snapshot_key = AppManager.charge_snapshot_cache_key(params[:shop],
|
|
143
|
+
snapshot_key = AppManager.charge_snapshot_cache_key(params[:shop], bound['timestamp'])
|
|
132
144
|
discount_snapshot = Rails.cache.read(snapshot_key) rescue nil
|
|
133
145
|
if discount_snapshot.is_a?(Hash)
|
|
134
146
|
discount_snapshot.each { |field, value| charge[field] = value unless value.nil? || value == '' }
|
|
@@ -141,7 +153,7 @@ module AppManager
|
|
|
141
153
|
if response['message'] == "success"
|
|
142
154
|
AppManager.clear_cache
|
|
143
155
|
|
|
144
|
-
update_info = {@plan_field =>
|
|
156
|
+
update_info = {@plan_field => plan_id,grandfathered_field => 0}
|
|
145
157
|
if !config_trial_days.nil? && !plan_data.nil?
|
|
146
158
|
trial_days = plan_data['trial_days'] || 0
|
|
147
159
|
update_info[config_trial_days] = trial_days
|
|
@@ -164,10 +176,10 @@ module AppManager
|
|
|
164
176
|
|
|
165
177
|
begin
|
|
166
178
|
plan_obj = AppManager::Client.new
|
|
167
|
-
if
|
|
168
|
-
discounted_plans = plan_obj.get_related_discounted_plans(
|
|
169
|
-
if discounted_plans.empty? || discounted_plans.include?(
|
|
170
|
-
plan_obj.discount_used(@shop[shopify_domain],
|
|
179
|
+
if discount_id.present? && discount_id != '0' && plan_data['is_global'] == 0
|
|
180
|
+
discounted_plans = plan_obj.get_related_discounted_plans(discount_id)
|
|
181
|
+
if discounted_plans.empty? || discounted_plans.include?(plan_id.to_i)
|
|
182
|
+
plan_obj.discount_used(@shop[shopify_domain], discount_id)
|
|
171
183
|
end
|
|
172
184
|
end
|
|
173
185
|
rescue Exception => e
|
|
@@ -196,7 +208,7 @@ module AppManager
|
|
|
196
208
|
redirect_to "#{app_url}?host=#{embed_host}&shop=#{params[:shop]}", :allow_other_host => true, :status => 301 and return
|
|
197
209
|
end
|
|
198
210
|
else
|
|
199
|
-
raise Error, "Invalid shopify charge #{charges.
|
|
211
|
+
raise Error, "Invalid shopify charge #{charges.code} #{charges.body.to_s[0, 500]}"
|
|
200
212
|
end
|
|
201
213
|
else
|
|
202
214
|
raise ModelNotFound, "Shop not found"
|
|
@@ -218,9 +230,8 @@ module AppManager
|
|
|
218
230
|
def cancel_charge
|
|
219
231
|
if params[:charge_id].present? && params[:shop].present?
|
|
220
232
|
@shop = shop_data
|
|
221
|
-
shopify_token = @field_names['shopify_token']
|
|
222
233
|
begin
|
|
223
|
-
gq_obj = AppManager::GraphqlHelper.new(@shop[@shopify_domain]
|
|
234
|
+
gq_obj = AppManager::GraphqlHelper.new(@shop[@shopify_domain])
|
|
224
235
|
rec_cancel_data = gq_obj.recurring_charge_cancel_api_call(params[:charge_id], @shop)
|
|
225
236
|
rescue Exception => e
|
|
226
237
|
Rollbar.error("APP MANAGER Cancel Plan Failed #{e.inspect}-#{e.backtrace}")
|
|
@@ -306,6 +317,15 @@ module AppManager
|
|
|
306
317
|
end
|
|
307
318
|
end
|
|
308
319
|
|
|
320
|
+
def redirect_to_app
|
|
321
|
+
embed_host = Base64.encode64(params[:shop] + "/admin")
|
|
322
|
+
if app_slug.present?
|
|
323
|
+
redirect_to "https://#{params[:shop]}/admin/apps/#{app_slug}", :allow_other_host => true
|
|
324
|
+
else
|
|
325
|
+
redirect_to "#{app_url}?host=#{embed_host}&shop=#{params[:shop]}", :allow_other_host => true, :status => 301
|
|
326
|
+
end
|
|
327
|
+
end
|
|
328
|
+
|
|
309
329
|
def app_url
|
|
310
330
|
AppManager.configuration.app_url
|
|
311
331
|
end
|