From 0a333f3a08e93be545471dd2cc8023c658a8dbb7 Mon Sep 17 00:00:00 2001 From: mbianco-stripe <45374579+mbianco-stripe@users.noreply.github.com> Date: Wed, 27 Jul 2022 18:45:05 -0700 Subject: [PATCH] Improved revised order product error, docs from walkthrough (#606) * Improve error message for missing revised line item * Stop connectionSuccessful, not used in latest JS code * Documentation from video walkthrough * Adding brian to pr template --- .github/pull_request_template/simple.md | 1 + app/controllers/sessions_controller.rb | 2 +- config/initializers/omniauth.rb | 12 +++++++++--- lib/stripe-force/db/user.rb | 3 ++- lib/stripe-force/translate/order.rb | 3 ++- sfdx/bin/extract-private-key | 3 +++ sfdx/bin/refresh-salesforce-credentials | 3 +-- .../systemConnectionsStep/systemConnectionsStep.js | 8 +++++++- 8 files changed, 26 insertions(+), 9 deletions(-) diff --git a/.github/pull_request_template/simple.md b/.github/pull_request_template/simple.md index a744b5c0bd..ab0103cdee 100644 --- a/.github/pull_request_template/simple.md +++ b/.github/pull_request_template/simple.md @@ -11,6 +11,7 @@ ### Notify r? @brennen-stripe +cc @brianw-stripe cc @arnoldezeolisa cc @sean-appiphony --> diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 462d6aad2c..2673a41b32 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -17,6 +17,7 @@ def root_action end end + # LWC "authorize" button hits this action def login_entrypoint oauth_type = params.require(:oauth_type) @@ -130,7 +131,6 @@ def stripe_callback EOL end diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb index e1294bf8c0..d850f4b275 100644 --- a/config/initializers/omniauth.rb +++ b/config/initializers/omniauth.rb @@ -1,11 +1,20 @@ # frozen_string_literal: true # typed: false +# defines these POST routes for us: +# - /auth/salesforcesandbox +# - /auth/salesforce +# - /auth/stripe +# +# callbacks are explicitly defined in routes.rb. The GET versions of these +# routes are defined in routes.rb. This is to work out around a oauth security issue. + Rails.application.config.middleware.use OmniAuth::Builder do provider :stripe, ENV["STRIPE_CLIENT_ID"], ENV["STRIPE_CLIENT_SECRET"], scope: 'read_write' provider :salesforce, ENV.fetch('SF_CONSUMER_KEY'), ENV.fetch('SF_CONSUMER_SECRET') + # same oauth consumer keys are used for sandbox & prod, but different destination URLs provider OmniAuth::Strategies::SalesforceSandbox, ENV['SF_CONSUMER_KEY'], ENV['SF_CONSUMER_SECRET'] @@ -13,6 +22,3 @@ ENV['SF_CONSUMER_KEY'], ENV['SF_CONSUMER_SECRET'] end - -# from sinatra -# OmniAuth.config.full_host = ENV.fetch("DOMAIN") diff --git a/lib/stripe-force/db/user.rb b/lib/stripe-force/db/user.rb index c985e36bae..04efb6014e 100644 --- a/lib/stripe-force/db/user.rb +++ b/lib/stripe-force/db/user.rb @@ -62,6 +62,7 @@ def sf_client end @client ||= Restforce.new({ + # this could be expired, if it is the client will automatically refresh it oauth_token: salesforce_token, refresh_token: salesforce_refresh_token, instance_url: sf_endpoint, @@ -79,7 +80,7 @@ def sf_client log_level: :debug, }.merge(optional_client_params)) - # TODO should we conditionally do this? + # TODO should refresh & persist the update https://jira.corp.stripe.com/browse/PLATINT-1718 # @client.authenticate! @client diff --git a/lib/stripe-force/translate/order.rb b/lib/stripe-force/translate/order.rb index fb78de29fd..0e4549cee9 100644 --- a/lib/stripe-force/translate/order.rb +++ b/lib/stripe-force/translate/order.rb @@ -464,7 +464,8 @@ def merge_subscription_line_items(aggregate_phase_items, new_phase_items) if existing_phase_item.nil? && new_subscription_item.original_order_line_id throw_user_failure!( salesforce_object: new_subscription_item.order_line, - message: "Any order items, revising order items in a previous order, must not be skipped in the previous order." + message: "Any order items, revising order items in a previous order, must not be skipped in the previous order." \ + " Order line with ID '#{new_subscription_item.original_order_line_id}' could not be found." ) end diff --git a/sfdx/bin/extract-private-key b/sfdx/bin/extract-private-key index 69119f5980..b08ffae34b 100755 --- a/sfdx/bin/extract-private-key +++ b/sfdx/bin/extract-private-key @@ -12,5 +12,8 @@ if [ -z "$SF_JWT_PRIVATE_KEY_PATH" ]; then exit 1 fi +# the certificate associated with this key is uploaded to our SF application on the billing PBO org +# this is the closest thing we have to a platform key in salesforce + # set `SF_JWT_KEY` on CI to `cat sfdx/jwt-cert/private_key.pem | base64` echo $SF_JWT_KEY | base64 --decode --ignore-garbage > $SF_JWT_PRIVATE_KEY_PATH diff --git a/sfdx/bin/refresh-salesforce-credentials b/sfdx/bin/refresh-salesforce-credentials index 7d14a1f1fb..23933d3390 100755 --- a/sfdx/bin/refresh-salesforce-credentials +++ b/sfdx/bin/refresh-salesforce-credentials @@ -10,8 +10,7 @@ if [ ! -z "$CI" ]; then exit 1 fi -cd "$(dirname "$0")" -cd .. +cd "$(dirname "$0")/.." while true; do echo "Refreshing..." diff --git a/sfdx/force-app/main/default/lwc/systemConnectionsStep/systemConnectionsStep.js b/sfdx/force-app/main/default/lwc/systemConnectionsStep/systemConnectionsStep.js index 11e2bd7bad..f83e95949d 100644 --- a/sfdx/force-app/main/default/lwc/systemConnectionsStep/systemConnectionsStep.js +++ b/sfdx/force-app/main/default/lwc/systemConnectionsStep/systemConnectionsStep.js @@ -7,6 +7,7 @@ export default class SystemConnectionsStep extends LightningElement { @track stripeComplete = false; @track connectWindow; @track isSandbox; + // TODO should be pulled from APEX @track rubyBaseURI = 'https://stripe-force.herokuapp.com'; @track salesforceNamespace; @api hideAction = false; @@ -23,6 +24,8 @@ export default class SystemConnectionsStep extends LightningElement { } else if (event.origin === this.rubyBaseURI && event.data === 'salesforceConnectionSuccessful') { this.connectWindow.close(); this.validateConnectionStatus(false, 'stripe'); + } else { + } } window.addEventListener("message", this.postMessageListener.bind(this)); @@ -30,8 +33,10 @@ export default class SystemConnectionsStep extends LightningElement { disconnectedCallback() { window.removeEventListener('message', this.postMessageListener); - } + } + // connected to the "Authorize" button in the UI + // main entry point for starting the authorization flow connectToStripe(event) { let oauthConnectionURL = this.rubyBaseURI; @@ -41,6 +46,7 @@ export default class SystemConnectionsStep extends LightningElement { oauthConnectionURL += '/auth/salesforce' } + // TODO should be removed since the namespace is defined via the post install ste[p] oauthConnectionURL += "?salesforceNamespace=" + this.salesforceNamespace this.connectWindow = window.open(oauthConnectionURL, '"_blank"');