forked from passportpayments/passportpayments-php
/
chargeCard.php
78 lines (54 loc) · 1.56 KB
/
chargeCard.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
68
69
70
71
72
73
74
75
76
77
78
<?php
if($_POST){
if(empty($_POST["amount"])){
$amountError="Missing amount";
}
else{
$params['amount']= test_input($_POST["amount"]);
}
$params['currency']="USD";
}
function test_input($data){
$data= trim($data);// remove whitespaces and predefined chars(<->'<') - both ends
$data= htmlspecialchars($data);// converts predefined chars and process the data and then returns.
return $data;
}
?>
<?php
if($_POST && $amountError=="" && $currencyError==""){
require_once('PassportPayments.php');
$appId = "37Z8ZDAZE8N";
$appSecret = "b2578c560673697eb49834b05a70aa1a";
$publicKey="37XI8CVAQSK";
$endPoint = 'https://sandbox.passportpayments.com';
$pp = new PassportPayments($appId, $appSecret, $publicKey, $endPoint);
$cardId= $_POST["cardId"];
$resp= $pp->captureByCardId($cardId,$params);
if($resp->status!=200){
echo "message: ".$resp->message."<br>";
}
else{
header('Location: listOfTransactions.php?cdid='.$cardId.'&cid='.$customerId.'');//no status exists-no error-success
}
}
else{
if($_GET)
$cardId=$_GET["cardId"] ;
else
$cardId=$_POST["cardId"];
?>
<!DOCTYPE HTML>
<html>
<body>
<h1> Charge Card </h1>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<input type="hidden" name="cardId" value="<?php echo $cardId;?>">
Amount*: <input type="number" name="amount" value="<?php echo $params['amount'];?>">
<span class="error"> <?php echo $amountError;?> </span>
<br><br><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
<?php
}?>