Skip to content

Commit e0a86ed

Browse files
Sample-Code for Chase Pay
1 parent ebab0ec commit e0a86ed

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
require 'vendor/autoload.php';
3+
require_once 'constants/SampleCodeConstants.php';
4+
use net\authorize\api\contract\v1 as AnetAPI;
5+
use net\authorize\api\controller as AnetController;
6+
7+
define("AUTHORIZENET_LOG_FILE", "phplog");
8+
9+
function createChasepayTransaction($amount)
10+
{
11+
/* Create a merchantAuthenticationType object with authentication details
12+
retrieved from the constants file */
13+
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
14+
$merchantAuthentication->setName(\SampleCodeConstants::MERCHANT_LOGIN_ID);
15+
$merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY);
16+
17+
// Set the transaction's refId
18+
$refId = 'ref' . time();
19+
20+
// Create the payment data for a credit card
21+
$creditCard = new AnetAPI\CreditCardType();
22+
$creditCard->setCardNumber("4111111111111111");
23+
$creditCard->setExpirationDate("2038-12");
24+
$creditCard->setCardCode("999");
25+
// Set the token specific info
26+
$creditCard->setIsPaymentToken(true);
27+
$creditCard->setCryptogram("EjRWeJASNFZ4kBI0VniQEjRWeJA=");
28+
$creditCard->setTokenRequestorName("CHASE_PAY");
29+
$creditCard->setTokenRequestorId("12345678901");
30+
$creditCard->setTokenRequestorEci("07");
31+
32+
$paymentOne = new AnetAPI\PaymentType();
33+
$paymentOne->setCreditCard($creditCard);
34+
35+
//create a transaction
36+
$transactionRequestType = new AnetAPI\TransactionRequestType();
37+
$transactionRequestType->setTransactionType("authCaptureTransaction");
38+
$transactionRequestType->setAmount($amount);
39+
$transactionRequestType->setPayment($paymentOne);
40+
41+
42+
$request = new AnetAPI\CreateTransactionRequest();
43+
$request->setMerchantAuthentication($merchantAuthentication);
44+
$request->setRefId( $refId);
45+
$request->setTransactionRequest( $transactionRequestType);
46+
$controller = new AnetController\CreateTransactionController($request);
47+
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
48+
49+
if ($response != null)
50+
{
51+
if($response->getMessages()->getResultCode() == "Ok")
52+
{
53+
$tresponse = $response->getTransactionResponse();
54+
55+
if ($tresponse != null && $tresponse->getMessages() != null)
56+
{
57+
echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n";
58+
echo "Charge Tokenized Credit Card AUTH CODE : " . $tresponse->getAuthCode() . "\n";
59+
echo "Charge Tokenized Credit Card TRANS ID : " . $tresponse->getTransId() . "\n";
60+
echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n";
61+
echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n";
62+
}
63+
else
64+
{
65+
echo "Transaction Failed \n";
66+
if($tresponse->getErrors() != null)
67+
{
68+
echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n";
69+
echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n";
70+
}
71+
}
72+
}
73+
else
74+
{
75+
echo "Transaction Failed \n";
76+
$tresponse = $response->getTransactionResponse();
77+
if($tresponse != null && $tresponse->getErrors() != null)
78+
{
79+
echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n";
80+
echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n";
81+
}
82+
else
83+
{
84+
echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n";
85+
echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n";
86+
}
87+
}
88+
}
89+
else
90+
{
91+
echo "No response returned \n";
92+
}
93+
94+
return $response;
95+
}
96+
if(!defined('DONT_RUN_SAMPLES'))
97+
createChasepayTransaction(12.23);
98+
?>

0 commit comments

Comments
 (0)