Repository navigation
Expand file tree
/
Copy pathpurchase.php
More file actions
79 lines (70 loc) · 3.47 KB
/
Copy pathpurchase.php
File metadata and controls
79 lines (70 loc) · 3.47 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
<!DOCTYPE html>
<html>
<head>
<title>Omnipay PayUnity driver POST recurring purchase example page</title>
</head>
<body>
<h1>Omnipay PayUnity driver POST recurring purchase example page</h1>
<?php
$urlBase = getenv('PAYUNITY_DRIVER_FOR_OMNIPAY_EXAMPLES_URL_BASE') ?: 'https://your.site.example/path/to/examples';
try {
$amount = '1.05';
echo '<div>Purchase of amount: '.$amount.'</div>'."\n";
$cardReference = isset($_POST['reference']) ? $_POST['reference'] : '';
/** @var \Omnipay\PayUnity\PostGateway $gateway */
$gateway = \Omnipay\Omnipay::create('PayUnity\\Post');
$gateway->setTestMode(true);
$gateway->setSecuritySender(getenv('PAYUNITY_SECURITY_SENDER') ?: '696a8f0fabffea91517d0eb0a0bf9c33');
$gateway->setTransactionChannel(getenv('PAYUNITY_TRANSACTION_CHANNEL') ?: '52275ebaf361f20a76b038ba4c806991');
$gateway->setUserLogin(getenv('PAYUNITY_USER_LOGIN') ?: '1143238d620a572a726fe92eede0d1ab');
$gateway->setUserPwd(getenv('PAYUNITY_USER_PWD') ?: 'demo');
$request = $gateway->purchase();
$request->setCardReference($cardReference);
$request->setAmount($amount);
$request->setCurrency('EUR');
$request->setDescription('Test purchase');
$response = $request->send();
$transactionReference = $response->getTransactionReference();
echo '<div>'.($response->isSuccessful() ? 'Success' : 'Failure').'</div>';
echo '<div>Message: '.$response->getMessage().'</div>';
echo '<div>Code: '.$response->getCode().'</div>';
echo '<div>Transaction reference:'.$transactionReference.'</div>';
echo '<h4>Data:</h4>';
echo '<code>';
var_dump($response->getData());
echo '</code>';
?>
<form action="<?php echo $urlBase; ?>/Post/purchase" method="post" target="_blank">
<label for="reference">Card reference:</label>
<input type="text" name="reference" style="width:40em" value="<?php echo $cardReference ?>">
<button type="submit">Make recurring payment with amount 1.05 Euro</button>
</form>
<br>
<form action="<?php echo $urlBase; ?>/Post/authorize" method="post" target="_blank">
<label for="reference">Card reference:</label>
<input type="text" name="reference" style="width:40em" value="<?php echo $cardReference ?>">
<button type="submit">Make recurring authorization with amount 2.15 Euro</button>
</form>
<br>
<form action="<?php echo $urlBase; ?>/Post/void" method="post" target="_blank">
<label for="reference">Card reference:</label>
<input type="text" name="reference" style="width:40em" value="<?php echo $cardReference ?>">
<label for="reference">Transaction reference:</label>
<input type="text" name="transaction" style="width:40em" value="<?php echo $transactionReference ?>">
<button type="submit">Void transaction</button>
</form>
<br>
<form action="<?php echo $urlBase; ?>/Post/refund" method="post" target="_blank">
<label for="reference">Card reference:</label>
<input type="text" name="reference" style="width:40em" value="<?php echo $cardReference ?>">
<label for="reference">Transaction reference:</label>
<input type="text" name="transaction" style="width:40em" value="<?php echo $transactionReference ?>">
<button type="submit">Partial refund 0.50 Euro</button>
</form>
<?php
} catch (Exception $e) {
echo '<div>An error happened. Code: '.$e->getCode().' Message: '.$e->getMessage().'</div>';
}
?>
</body>
</html>