Environment variable / GoCardless payments integration

Hello, I’m trying to design a basic integration with GoCardless, whereby notifications are sent to the CRM using a Webhook and I’ll store each one as a new record in a list.

See: https://developer.gocardless.com/getting-started/api/staying-up-to-date-with-webhooks/

I got as far as proving out the solution by using the following code, placed early on in the file;
$bean = BeanFactory::newbean(‘TestModule’);
$bean->name=‘BeansOnToast’;
$bean->save();

I even replaced ‘BeansOnToast’ with $request_body with success. However, if I place it after this bit of code, it didn’t work…

try {
$events = \GoCardlessPro\Webhook::parse($request_body,
$signature_header,
$webhook_endpoint_secret);

Honestly, I don’t understand the above code, but apparently it doesn’t pass this point in mine.

I also don’t really know where to store an environment variable, so this might be related. I’ve tried replacing the following bit:
$webhook_endpoint_secret = “code copied from GoCardless”;

Any advice?

Thanks, Mike

1 Like

@menness
I think that your question about gocardless but not about SuiteCRM.

Well … yeah

Anyway I found the issue… obviously it stopped working at the point where it goes looking for a function in \GoCardlessPro\Webhook … and I had failed to install the GoCardless files.

Problem solved, nothing to do with environment variables haha.

1 Like

i want to support you because i need Gocardless addons!

Happy to share what I learned… maybe others can benefit.

First learned how to create an entry point by watching YouTube:

And how to create a new record using code:

Then I read the GoCardless code until I roughly understood roughly how to do it. Below is my terrible PHP which will probably break at some point… happy to accept feedback / improvements on it, but it basically works.

Note, the below method isn’t very secure as someone could spoof a fake payment unless you check the signature - not implemented that yet.

<?php
$request_body = file_get_contents('php://input');
$headers = getallheaders();
$signature_header = $headers["Webhook-Signature"];

//Uncomment this bit for testing the webhook url directly
//$request_body='{"events":[{"id":"EVTESTVK7X5BVZ","created_at":"2021-03-20T13:18:59.307Z","resource_type":"payments","action":"customer_approval_denied","links":{"payment":"index_ID_123"},"details":{"origin":"customer","cause":"customer_approval_denied","description":"The customer denied approval for this payment"},"metadata":{}}],"meta":{"webhook_id":"WB003F7Z6PR8GR"}}';
//echo $request_body;
    
    $events = json_decode($request_body)->events;
    $eventsarray = array_map('self::buildEvent', $events);
    
    foreach ($events as $event) {
        //print("Processing event " . $event->id . "\n");
        
        $bean = BeanFactory::newbean('GoCardlessUpdatesList');
        $bean->name=$event->id;
        $bean->type=$event->resource_type;
        $bean->action_c=$event->action;
        $bean->event_details_c=$event->details->description;
        $bean->cause_c=$event->details->cause;
        $bean->links_c=var_export($event->links, true);
        $bean->description=var_export($event, true);
        $bean->save();
        
        echo "saved to CRM.  ID: ";
        echo $bean->name;
        echo '<pre>'.var_export($event, true).'</pre>';
        
    }
    header("HTTP/1.1 200 OK");