Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Dynamic WebHook URL Definition and Callback Dispatch Event #24

Open
solverat opened this issue Feb 10, 2023 · 0 comments
Open

Allow Dynamic WebHook URL Definition and Callback Dispatch Event #24

solverat opened this issue Feb 10, 2023 · 0 comments

Comments

@solverat
Copy link

solverat commented Feb 10, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant