The following provides a set of steps that will get you setup to use the Smarterpay Cloud for Salesforce managed package with the default settings. An explanation of these settings and more customisation options can be found under the 'Additional Settings' section.
SmarterPay Cloud API communication uses Named Credentials.
Go to Setup → Named Credentials → External Credentials
Select 'Smarter Pay Cloud UAT' or 'SmarterPay Cloud Live' depending on which instance you are configuring.
For this step you will need to get your API Key from your SmarterPay Cloud account. This can be found in the SmarterPay Cloud System Settings area.
In the External Named Credential, click the 'New' button on the 'Custom Header' section. Here we are entering the API Key that will be used to communicate with SmarterPay Cloud. Populate this custom header with the details below, using your API Key.
Custom Header:
Name: Authorization Value: Bearer [Your SmarterPay Cloud API KEY] Sequence Number: 1
Warning
Ensure there is only one space between the word 'Bearer' and your API Key.
You must now tell Salesforce which users can use the Named Credential.
Simply assign the in-built 'SmarterPay Admin' or 'SmarterPay User' permission set to enable access.
Using OAuth to authenticate the webhook connection is the recommended method for the SmarterPay package.
You will need to generate a webhook key with a length of up to 45 characters. We would recommend a 128bit or 256bit key length. There are several free services that can do this for you. Keep this key handy, we will need it later. This key is used to verify that the webhook is coming from SmarterPay Cloud.
Go to the SmarterPay Setup tab in Salesforce under the SmarterPay App. Enter the webhook key that you created under the 'Webhook Private Key' field and click save next to the input field. Note: To maintain security, you will only be able to update this value in Salesforce and will not be able to see what is currently set.
Open SmarterPay Cloud and go to Subscriptions in the Setup area. Click 'New Subscription'. See the screenshot below for the recommended settings.
In the security section choose 'OAuth' which should provide you with the following fields:
Populate the following fields using the format below:
AUTHORISATION ENDPOINT | https://salesforcedomain.my.salesforce.com/services/oauth2/authorize |
WEBHOOK URL | https://salesforcedomain.my.salesforce.com/services/apexrest/SmarterPay/WebhookV2Receiver |
TOKEN ENDPOINT | https://salesforcedomain.my.salesforce.com /services/oauth2/token |
WEBHOOK SIGNATURE KEY | Webhook Key generated in step 1 |
Under 'Events' select all events with all sources.
Once done, click 'Save'. You will now see your new SmarterPay Cloud subscription. Please note, these new settings can take up to 30 minutes to propagate to our backend systems.
To activate the subscription you will need:
Click 'Setup Auth' to start the activation process. This will ask if you want to be forwarded you to the relevant endpoint for Authorisation. Confirm by clicking 'Ok'.
You will now be forwarded to the Salesforce login screen. Enter the username and password of the user you wish to use for the integration.
On successfully setting up the OAuth you'll be redirected to Cloud which will show the following message:
Warning
SmarterPay does not recommend this approach and should only be used as a fallback if your organisation is unable to accommodate OAuth connections.
You will need to generate a webhook key with a length of up to 45 characters. We would recommend a 128bit or 256bit key length. There are several free services that can do this for you. Keep this key handy, we will need it later. This key is used to verify that the webhook is coming from SmarterPay Cloud.
Go to the SmarterPay Setup tab in Salesforce under the SmarterPay App. Enter the webhook key that you created under the 'Webhook Private Key' field and click save next to the input field. Note: To maintain security, you will only be able to update this value in Salesforce and will not be able to see what is currently set.
Now we need to create a Salesforce Site. Once saved, make a note of the full URL. Setup → Sites → New You can create a site with the any details you want, but we would recommend the following:
Finally, we need to give access to the Webhook Receiver apex class. To do this, click 'Public Access Settings' and scroll down to 'Enabled Apex Class Access'. Click 'Edit' and select 'SmarterPay.WebhookV2Receiver'.
Open SmarterPay Cloud and go to Subscriptions in the Setup area. Click 'New Subscription'. See the screenshot below for the recommended settings. You will need to enter your webhook key and Salesforce Sites URL you made earlier.
Under 'Events' select all events with all sources.
Once done, click 'Save'. You will now see your new SmarterPay Cloud subscription. Please note, these new settings can take up to 30 minutes to propagate to our backend systems
Additional details of SmarterPay Clouds Webhooks 'Signature' Subscriptions can be found in our wiki: https://wiki.smarterpay.com/smarterpaycloud/webhooks/signature
Cloud can handle multiple Service User Numbers; these must be configured in the Custom Metadata to ensure that the records are set up against the corresponding SUN.
When webhooks are processed via a Platform Event by default it is executed in the context of the 'Automated Process' user. Most of the time this is absolutely fine, however there may be instances where you wish to change the running user to another user in the system, such as an Administrator. Typically this is required when some additional automation is run, via a Trigger or Flow, that requires additional permissions that the Automated Process User is unable to have.
To change the running user for the Platform Event we can add a PlatformEventSubscriber record.