Blackthorn | Scheduled Jobs
  • 11 Dec 2023
  • 2 Minutes to read
  • Dark
    Light

Blackthorn | Scheduled Jobs

  • Dark
    Light

Article Summary

You can find the scheduled jobs below in Setup. In the Quick Find box, enter and click "Scheduled Jobs". All of the Payments job names start with Blackthorn | Payments.

  • Blackthorn | Payments Send Stripe Invoices - It runs at 6 am each day to send the Invoice to the customer when Send Invoice On Date = "TODAY" on the Invoice.
  • Blackthorn | Payments Past Due Invoices - It runs at 5 am each day to update the Invoice Payment Status = "Past Due" when the Due Date < Today and Payment Status = "Unpaid".

You can schedule the jobs listed above by clicking the Schedule Billing Jobs button in the Blackthorn | Payment Admin tab.

Process Stripe Billing Webhook Types Asynchronously

A global method that allows customers to process certain Stripe Billing webhook types asynchronously instead of via the Blackthorn batch jobs was added. If the Process Async checkbox = “True”, the existing web processing batch jobs will skip those webhooks.

Blackthorn customers are responsible for adding the logic that 1) sets the records they want as Process Async and 2) calls the async method to process them. The following example code creates a before trigger to check the Process Async box and an after trigger to call the async method.

Before proceeding, two updates must be made to the Site Guest User/public user.

Step 1: To avoid permission errors, give the Blackthorn | Payments (Site Guest User) permission set Read access to the Product (Product2) object.

  1. Click the Gear icon in the upper right-hand corner.
  2. Click Setup.
  3. In the Quick Find box, enter and click “Permission Sets.”
  4. Create a new permission set.
    1. Click New.
    2. In the Label field, enter a descriptive name for the permission set, such as “Read Access to Product2.”
    3. Click Save.
  5. Configure object permissions.
    1. Click “Object Settings” or “Object Permissions” in the Apps section.
    2. Find and click the Product (Product2) object. If you don’t see it, use the search function to locate it.
    3. Click Edit next to the Products heading.
    4. In the Object Permissions section, set Read to “Enabled” (checked). Do not enable Edit, Create, and Delete unless they are needed.
    5. Click Save.

Step 2: Assign the newly created permission set to the public user.

  1. Navigate back to the site you created.
  2. Click Public Access Settings.
  3. Click the View Users or Assign Users button.
  4. Click the link for the site guest user.
  5. In the Permission Set Assignments section, click Edit Assignments.
  6. Move the newly created permission set from the Available Permission Sets column to the Enabled Permission Sets column.
  7. Click Save.
trigger customWebhookTrigger on Webhook_Event__c (before insert, after insert) {
    if (Trigger.isBefore) {
        for (bt_stripe__Webhook_Event__c webhook : Trigger.new) {
            if (webhook.bt_stripe__Type__c == 'invoice.created') {
                webhook.bt_stripe__Process_Async__c = true;
            }
        }
    }

    if (Trigger.isAfter) {
        List<Webhook_Event__c> webhooks = [SELECT Id, Name, Type__c, Process_Async__c, Processed__c, Payment_Gateway__c, Data__c FROM Webhook_Event__c WHERE Id IN :trigger.new];
        for (Webhook_Event__c webhook : webhooks) {
            if (webhook.bt_stripe__Process_Async__c && webhook.bt_stripe__Type__c == 'invoice.created') {
                // Call without sharing class here to process the webhook
            }
        }
    }
}

NOTE: Replace 'invoice.created' or add additional webhook types as needed.


What's Next