forked from AuthorizeNet/sample-code-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvoid.php
More file actions
60 lines (47 loc) · 1.91 KB
/
void.php
File metadata and controls
60 lines (47 loc) · 1.91 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
<?php
require 'vendor/autoload.php';
use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;
define("AUTHORIZENET_LOG_FILE", "phplog");
function payPalVoid($transactionId) {
// Common setup for API credentials
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID);
$merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY);
$refId = 'ref' . time();
$payPalType = new AnetAPI\PayPalType();
$payPalType->setSuccessUrl("");
$payPalType->setCancelUrl("");
$paymentType = new AnetAPI\PaymentType();
$paymentType->setPayPal($payPalType);
$transactionRequest = new AnetAPI\TransactionRequestType();
$transactionRequest->setTransactionType("voidTransaction");
$transactionRequest->setPayment($paymentType);
$transactionRequest->setRefTransId($transactionId);
$request = new AnetAPI\CreateTransactionRequest();
$request->setMerchantAuthentication($merchantAuthentication);
$request->setRefId( $refId);
$request->setTransactionRequest($transactionRequest);
$controller = new AnetController\CreateTransactionController($request);
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
if ($response != null)
{
$tresponse = $response->getTransactionResponse();
if (($tresponse != null) && ($tresponse->getResponseCode()=="1") )
{
echo "Void transaction SUCCESS TRANS ID : " . $tresponse->getTransId() . "\n";
}
else
{
echo "Void transaction ERROR : " . $tresponse->getResponseCode() . "\n";
}
}
else
{
echo "Void transaction Null esponse returned";
}
return $response;
}
if(!defined('DONT_RUN_SAMPLES'))
payPalVoid("2241706281");
?>