-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.php
More file actions
118 lines (96 loc) · 3.27 KB
/
index.php
File metadata and controls
118 lines (96 loc) · 3.27 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
107
108
109
110
111
112
113
114
115
116
117
118
<!DOCTYPE HTML>
<html>
<body>
<h1>Test Payment</h1>
<?php
/***************************************************
* INITIAL CONFIGURATION *
***************************************************
* ( SET UP THE ENVIRONMENT WITH YOUR CODES) *
***************************************************/
/**
* put this variable to true to pay on the test environment.
* To retrieve your test code you can sign in at http://docs.gestpay.it/test/sign-up-for-test-environment.html
*/
$test_env = true;
/*
* the shopLogin code
*/
$shopLogin = 'GESPAYXXXX';
/*
* the currency code.
* Check http://api.gestpay.it/#currency-codes for the right one
* '242' is the code for EURO.
*/
$currency = '242';
/**
* the amount of the transaction. How much do you want to bill your customers?
*/
$amount = '10.05';
/**
* This is the
*/
$shopTransactionID='MY-SHOP-001';
/***************************************************
* GESTPAY CODE *
***************************************************/
//used to display errors and to print the IP address of the server.
require('functions.php');
displayErrors();
printIpAddress();
//check where to connect: test or production environment?
if ($test_env) {
$wsdl = "https://sandbox.gestpay.net/gestpay/gestpayws/WSCryptDecrypt.asmx?WSDL"; //TESTCODES
$action_pagamento = "https://sandbox.gestpay.net/pagam/pagam.aspx";
} else {
$wsdl = "https://ecomms2s.sella.it/gestpay/gestpayws/WSCryptDecrypt.asmx?WSDL"; //PRODUCTION
$action_pagamento = "https://ecomm.sella.it/pagam/pagam.aspx";
}
//create the payment object array
$param = array(
'shopLogin' => $shopLogin
,'uicCode' => $currency
,'amount' => $amount
,'shopTransactionId' => $shopTransactionID
);
//instantiate a SoapClient from Gestpay Wsdl
$client = new SoapClient($wsdl);
$objectResult = null;
//do the call to Encrypt method
try {
$objectResult = $client->Encrypt($param);
}
//catch SOAP exceptions
catch (SoapFault $fault) {
trigger_error("SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})", E_USER_ERROR);
}
//parse the XML result
$result = simplexml_load_string($objectResult->EncryptResult->any);
// if there is an error trying to contact Gestpay Server
// (e.g. your IP address is not recognized, or the shopLogin is invalid) you'll see it here.
$errCode= $result->ErrorCode;
$errDesc= $result->ErrorDescription;
if($errCode != 0){
echo "<h2>Error: $errCode - $errDesc</h2>";
echo '<h3>check the error in the <a href="http://api.gestpay.it/#errors">API</a></h3>';
die();
}
//finally, we will define the variable $encString that will contain a string to pass to Gestpay upon payment.
//See the form below how it is used.
$encString= $result->CryptDecryptString;
?>
We will start a payment with this data: <br>
shopLogin: <?= $shopLogin ?><br>
amount: <?= $amount ?> €
<!--hidden form, with cyphered data to start the payment process -->
<form
name="pagamento"
method="post"
id="fpagam"
action="<?= $action_pagamento ?> ">
<input name="a" type="hidden" value="<?php echo($shopLogin) ?>" />
<input name="b" type="hidden" value="<?php echo($encString) ?>" />
<input style="width:90px;height:70px" type="submit" name="Pay" Value="Pay Now!" />
</form>
</body>
</html>