Skip to content

Commit

Permalink
Improved revised order product error, docs from walkthrough (#606)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mbianco-stripe authored Jul 28, 2022
1 parent f8491bc commit 0a333f3
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/pull_request_template/simple.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
### Notify
r? @brennen-stripe
cc @brianw-stripe
cc @arnoldezeolisa
cc @sean-appiphony
-->
2 changes: 1 addition & 1 deletion app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def root_action
end
end

# LWC "authorize" button hits this action
def login_entrypoint
oauth_type = params.require(:oauth_type)

Expand Down Expand Up @@ -130,7 +131,6 @@ def stripe_callback
<script type="application/javascript">
window.opener.postMessage("salesforceConnectionSuccessful", "#{postmessage_domain}")
window.opener.postMessage("connectionSuccessful", "#{postmessage_domain}")
</script>
EOL
end
Expand Down
12 changes: 9 additions & 3 deletions config/initializers/omniauth.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
# 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']
provider OmniAuth::Strategies::SalesforcePreRelease,
ENV['SF_CONSUMER_KEY'],
ENV['SF_CONSUMER_SECRET']
end

# from sinatra
# OmniAuth.config.full_host = ENV.fetch("DOMAIN")
3 changes: 2 additions & 1 deletion lib/stripe-force/db/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/stripe-force/translate/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions sfdx/bin/extract-private-key
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions sfdx/bin/refresh-salesforce-credentials
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ if [ ! -z "$CI" ]; then
exit 1
fi

cd "$(dirname "$0")"
cd ..
cd "$(dirname "$0")/.."

while true; do
echo "Refreshing..."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,15 +24,19 @@ 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));
}

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;

Expand All @@ -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"');
Expand Down

0 comments on commit 0a333f3

Please sign in to comment.