Skip to content

Allow Dynamic WebHook URL Definition and Callback Dispatch Event #24

@solverat

Description

@solverat

Webhook URL

In JSON API, it's possible to define a custom webhook URL (webhook.url):

https://api-reference.datatrans.ch/#tag/v1transactions/operation/init

It would be nice to have the same in the payment-button context:

PaymentButton.init({
  webhook: {
    url: 'domain.com/xy'
})

Callback Dispatch Event

In our workflow, a payment entity needs to be created remotely, before any further (datatrans) actions can be dispatched (That's why we also need that dynamic webhook).

If a user dispatches the "Pay with apple/google" button, we need to push some data to our server first to initiate the payment. The response of this request also returns the webhook URL.

Exemplary code:

PaymentButton.on('dispatch', function (callback, initConfiguration) {

    fetch('https://domain.com/init-payment', {
        method: 'POST',
        body: JSON.stringify({foo: bar})
    })
    .then(response => response.json())
    .then(data => {

        // override init configuration
        initConfiguration.webhook.url = data.webhookUrl;

        // tell datatrans to proceed
        callback(initConfiguration);

    });
});

Otherwise, we're not able to prepare a payment item, which your service tries to allocate later by server to server communication. Hope this makes sense.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions