forked from bluem-development/bluem-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
payments-webhook.php
67 lines (52 loc) · 2.3 KB
/
payments-webhook.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/**
* Bluem-PHP examples: Webhook for payments
* This file contains examples and annotations for using the `bluem-php` package.
* All to-dos are for your reference where action on your part is still required.
*
* Code is courtesy of and property of Bluem Payment Services
* Author: Bluem Plugin Support ([email protected])
*/
require_once __DIR__.'/initialization.php';
/*
* Creating a webhook
*
* when running this in a webserver, this allows you to expose the webhook to the url like this:
*
* http:https://example.com/payments-webhook.php?action=webhook
*
* change this URL to match your web server.
*/
// This GET parameter is an example. This is not required.
if ($_GET['action'] === "webhook") {
// if you want debug information and verbose results when testing the webhook, set this to true
$bluem_object->setConfig("webhookDebug", false);
// this call will exit with a 200 or 400 HTTP status code, and parse the incoming data
// Returns null if the webhook didn't parse successfully.
$webhook = $bluem_object->Webhook();
// implement this like you implemented the callback for the regular services in your application
if ($webhook !== null) {
$status = $webhook->getStatus();
if ($status === "Success") {
$transactionID = $webhook->getTransactionID();
$amount = $webhook->getAmount();
$amountPaid = $webhook->getAmountPaid();
$currency = $webhook->getCurrency();
$paymentMethod = $webhook->getPaymentMethod();
// note: these are currently iDEAL specific
$debtorAccountName = $webhook->getDebtorAccountName();
$debtorIBAN = $webhook->getDebtorIBAN();
$debtorBankID = $webhook->getDebtorBankID();
// deal with the successful callback
} elseif($status ==="Cancelled") {
// deal with the cancelled callback
} elseif($status ==="Open") {
// deal with the open callback
} elseif($status ==="Expired"){
// deal with the failed or expired callback
} else {
// deal with any other status
}
// refer to the readme on webhooks for example methods to use for retrieving data from the callback object.
}
}