-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdo_purchase.php
More file actions
106 lines (69 loc) · 2.99 KB
/
do_purchase.php
File metadata and controls
106 lines (69 loc) · 2.99 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
namespace FraudPointer\API;
require_once dirname(__FILE__) . "/Fraudpointer/API/IClient.php";
require_once dirname(__FILE__) . "/helpers/Application.php";
session_start();
// check whether we have to start over
CheckForStartOver();
//-------------------------------------
// access necessary SESSION variables
$client = $_SESSION["fraudpointer_client"];
$assessment_session = GetOrCreateAssessmentSession($client);
$number_of_failed_payment_attempts = $_SESSION["number_of_failed_payment_attempts"];
$acme_order_number = $_SESSION["acme_order_number"];
// create and send checkout event
CreateAndSendCheckoutEvent($client, $assessment_session);
// I do not have any more data to send to server, I will ask for Fraud Assessment, an "interim" one not final
$fraud_assessment = $client->CreateFraudAssessment($assessment_session, true);
?>
<html>
<head>
<title>Result of Payment</title>
</head>
<body>
<?php
if ( $fraud_assessment->result == "Accept" ) { ?>
<?php
$charge_result = SendDataToBankForCharging();
if ( $charge_result ) {
// let us create a successful payment event
CreateAndSendSuccessfulPaymentEvent($client, $assessment_session);
$fraud_assessment = $client->CreateFraudAssessment($assessment_session, false);
ResetSessionVars();
?>
<h2>You have been successfully charged. Go <a href="index.php">BACK to purchase again!</a></h2>
<?php }
else {
CreateAndSendFailedPaymentEvent($client, $assessment_session);
$number_of_failed_payment_attempts = $number_of_failed_payment_attempts + 1;
$_SESSION["number_of_failed_payment_attempts"] = $number_of_failed_payment_attempts;
if ( $number_of_failed_payment_attempts > 3 ) {
// too many failed payment attempts
ResetSessionVars();
header("Location: index.php");
exit();
} // when number of failed payment attempts > 3
else {
header("Location: checkout.php");
exit();
} // when number of failed payment attempts <= 3
} // when payment to bank failed
?>
<?php
}
elseif ( $fraud_assessment->result == "Review" ) {
ResetSessionVars();
?>
<h1>We will hold your purchase request data and come back to you soon. Sorry for the delay. (<a href="index.php">[ACME Home Page]</a>)</h1>
<?php
}
else { // this is a Reject case
$fraud_assessment = $client->CreateFraudAssessment($assessment_session, false);
ResetSessionVars();
?>
<h1>Sorry, but we cannot process your request. Your data has been declined.</h1>
<?php
}
?>
</body>
</html>