Skip to content

Commit

Permalink
Merge branch 'release/0.18.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinballard committed Oct 11, 2021
2 parents 008c206 + 48703fc commit 7c640e4
Show file tree
Hide file tree
Showing 18 changed files with 2,026 additions and 2,021 deletions.
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
nodejs 13.7.0
postgres 10.4
ruby 2.6.5
yarn 1.22.10
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Change Log
All notable changes to this project will be documented in this file.

## 0.18.4 - 2021-10-11
### Changed
- Address the [Shopify API deprecation of charge activation](https://shopify.dev/changelog/auto-activation-of-charges-and-subscriptions)

## 0.18.3 - 2021-07-23
### Changed
- Address the [Shopify API deprecation of page-based pagination](https://shopify.dev/changelog/page-based-pagination-replaced-by-cursor-based-pagination-across-multiple-rest-endpoints) in favour of cursor-based in the `Synchronises` concern.
Expand Down
3 changes: 3 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ This file contains more detailed instructions on what's required when updating
an application between one release version of the gem to the next. It's intended
as more in-depth accompaniment to the notes in `CHANGELOG.md` for each version.

## Upgrading from 0.18.3 to 0.18.4
No changes required.

## Upgrading from 0.18.2 to 0.18.3
The `synchronise_all` method for models with the `Synchronises` concern has been updated to use cursor-based pagination per the [Shopify API deprecation](https://shopify.dev/changelog/page-based-pagination-replaced-by-cursor-based-pagination-across-multiple-rest-endpoints). Ad hoc app code updates to address this may now be removed.

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.18.3
0.18.4
7 changes: 6 additions & 1 deletion app/controllers/disco_app/charges_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ def create
end
end

# Attempt to activate a charge after a user has accepted or declined it.
# Attempt to activate a charge (locally) after a user has accepted or declined it.
# Redirect to the main application's root URL immediately afterwards - if the
# charge wasn't accepted, the flow will start again.
#
# Previously, the activation of a charge also required updating Shopify via the
# API, but that requirement has been removed.
#
# See https://shopify.dev/changelog/auto-activation-of-charges-and-subscriptions
def activate
# First attempt to find a matching charge.
if (charge = @subscription.charges.find_by(id: params[:id], shopify_id: params[:charge_id])).nil?
Expand Down
20 changes: 9 additions & 11 deletions app/services/disco_app/charges_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@ def self.create(shop, subscription)
charge
end

# Attempt to activate the given Shopify charge for the given Shop using the
# Shopify API. Returns true on successful activation, false otherwise.
# Synchronises the status of a given charge from the Shopify API and returns
# true if it's active (and false otherwise).
#
# Previously, the activation of a charge also required updating Shopify via the
# API, but that requirement has been removed.
#
# See https://shopify.dev/changelog/auto-activation-of-charges-and-subscriptions
def self.activate(shop, charge)
# Start by fetching the Shopify charge to check that it was accepted.
shopify_charge = shop.with_api_context do
Expand All @@ -43,20 +48,13 @@ def self.activate(shop, charge)
# Update the status of the local charge based on the Shopify charge.
charge.send("#{shopify_charge.status}!") if charge.respond_to? "#{shopify_charge.status}!"

# If the charge wasn't accepted, fail and return.
return false unless charge.accepted?

# If the charge was indeed accepted, activate it via Shopify.
charge.shop.with_api_context do
shopify_charge.activate
end
# If the charge isn't active, fail and return.
return false unless charge.active?

# If the charge was recurring, make sure that all other local recurring
# charges are marked inactive.
cancel_recurring_charges(shop, charge) if charge.recurring?

charge.active!

true
rescue StandardError
false
Expand Down
2 changes: 1 addition & 1 deletion initialise.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fi
APP_NAME="$1"
RAILS_VERSION="${RAILS_VERSION:-6.0.2}"
NODE_VERSION="${NODE_VERSION:-13.7.0}"
DISCO_APP_VERSION="${DISCO_APP_VERSION:-0.18.3}"
DISCO_APP_VERSION="${DISCO_APP_VERSION:-0.18.4}"

if [ -z $APP_NAME ]; then
echo ''
Expand Down
2 changes: 1 addition & 1 deletion lib/disco_app/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module DiscoApp

VERSION = '0.18.3'.freeze
VERSION = '0.18.4'.freeze

end
3 changes: 1 addition & 2 deletions test/controllers/disco_app/charges_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ def teardown
end

test 'user trying to activate accepted charge succeeds and is redirected to the root page' do
stub_api_request(:get, "#{@shop.admin_url}/recurring_application_charges/654381179.json", 'widget_store/charges/get_accepted_recurring_application_charge')
stub_api_request(:post, "#{@shop.admin_url}/recurring_application_charges/654381179/activate.json", 'widget_store/charges/activate_recurring_application_charge')
stub_api_request(:get, "#{@shop.admin_url}/recurring_application_charges/654381179.json", 'widget_store/charges/get_active_recurring_application_charge')

@current_subscription.active_charge.destroy
get :activate, params: { subscription_id: @current_subscription, id: @new_charge.id, charge_id: @new_charge.shopify_id }
Expand Down
6 changes: 4 additions & 2 deletions test/dummy/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"dependencies": {
"@rails/webpacker": "^4.0.7"
"@rails/webpacker": "5.4.3",
"webpack": "^4.46.0",
"webpack-cli": "^3.3.12"
},
"devDependencies": {
"webpack-dev-server": "^3.9.0"
"webpack-dev-server": "^3"
}
}
Loading

0 comments on commit 7c640e4

Please sign in to comment.