Skip to content

Commit 522e391

Browse files
committed
Adding new APIs
1 parent 01c1abb commit 522e391

File tree

8 files changed

+182
-21
lines changed

8 files changed

+182
-21
lines changed

CustomerProfiles/create-customer-payment-profile.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
function createCustomerPaymentProfile($existingcustomerprofileid, $phoneNumber){
99
// Common setup for API credentials
1010
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
11-
$merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID);
11+
$merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID);
1212
$merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY);
1313
$refId = 'ref' . time();
1414

@@ -37,6 +37,7 @@ function createCustomerPaymentProfile($existingcustomerprofileid, $phoneNumber){
3737
$paymentprofile->setCustomerType('individual');
3838
$paymentprofile->setBillTo($billto);
3939
$paymentprofile->setPayment($paymentCreditCard);
40+
$paymentprofile->setDefaultPaymentProfile(true);
4041

4142
$paymentprofiles[] = $paymentprofile;
4243

@@ -63,5 +64,5 @@ function createCustomerPaymentProfile($existingcustomerprofileid, $phoneNumber){
6364
return $response;
6465
}
6566
if(!defined('DONT_RUN_SAMPLES'))
66-
createCustomerPaymentProfile("36152127","000-000-0009");
67+
createCustomerPaymentProfile("1807545561","000-000-0009");
6768
?>

CustomerProfiles/create-customer-profile.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
function createCustomerProfile($email){
99

10-
// Common setup for API credentials
11-
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
10+
// Common setup for API credentials
11+
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
1212
$merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID);
1313
$merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY);
1414
$refId = 'ref' . time();

CustomerProfiles/get-accept-customer-profile-page.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
define("AUTHORIZENET_LOG_FILE", "phplog");
77

8-
function GetAcceptCustomerProfilePage($customerprofileid = "123212")
8+
function getAcceptCustomerProfilePage($customerprofileid = "123212")
99
{
1010
// Common setup for API credentials
1111
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
require 'vendor/autoload.php';
3+
use net\authorize\api\contract\v1 as AnetAPI;
4+
use net\authorize\api\controller as AnetController;
5+
6+
define("AUTHORIZENET_LOG_FILE", "phplog");
7+
8+
function getHostedPaymentPage($customerprofileid = "123212")
9+
{
10+
// Common setup for API credentials
11+
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
12+
$merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID);
13+
$merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY);
14+
$refId = 'ref' . time();
15+
16+
// Create the payment data for a credit card
17+
$creditCard = new AnetAPI\CreditCardType();
18+
$creditCard->setCardNumber("4111111111111111");
19+
$creditCard->setExpirationDate("1226");
20+
$creditCard->setCardCode("123");
21+
$paymentOne = new AnetAPI\PaymentType();
22+
$paymentOne->setCreditCard($creditCard);
23+
24+
$order = new AnetAPI\OrderType();
25+
$order->setDescription("New Item");
26+
27+
//create a transaction
28+
$transactionRequestType = new AnetAPI\TransactionRequestType();
29+
$transactionRequestType->setTransactionType( "authCaptureTransaction");
30+
$transactionRequestType->setAmount("12.23");
31+
32+
// Use an existing payment profile ID for this Merchant name and Transaction key
33+
34+
$setting = new AnetAPI\SettingType();
35+
$setting->setSettingName("hostedPaymentButtonOptions");
36+
$setting->setSettingValue("{\"text\": \"Pay\"}");
37+
$setting2 = new AnetAPI\SettingType();
38+
$setting2->setSettingName("hostedPaymentOrderOptions");
39+
$setting2->setSettingValue("{\"show\": false}");
40+
41+
//$alist = new AnetAPI\ArrayOfSettingType();
42+
//$alist->addToSetting($setting);
43+
44+
$request = new AnetAPI\GetHostedPaymentPageRequest();
45+
$request->setMerchantAuthentication($merchantAuthentication);
46+
$request->setTransactionRequest($transactionRequestType);
47+
48+
$request->addToHostedPaymentSettings($setting);
49+
$request->addToHostedPaymentSettings($setting2);
50+
51+
$controller = new AnetController\GetHostedPaymentPageController($request);
52+
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
53+
54+
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") )
55+
{
56+
echo $response->getToken()."\n";
57+
}
58+
else
59+
{
60+
echo "ERROR : Failed to get hosted profile page\n";
61+
$errorMessages = $response->getMessages()->getMessage();
62+
echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n";
63+
}
64+
return $response;
65+
}
66+
if(!defined('DONT_RUN_SAMPLES'))
67+
getHostedPaymentPage();
68+
?>
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
require 'vendor/autoload.php';
3+
use net\authorize\api\contract\v1 as AnetAPI;
4+
use net\authorize\api\controller as AnetController;
5+
6+
define("AUTHORIZENET_LOG_FILE", "phplog");
7+
8+
function updateHeldTransaction(){
9+
// Common setup for API credentials
10+
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
11+
$merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID);
12+
$merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY);
13+
$refId = 'ref' . time();
14+
15+
// Create the payment data for a credit card
16+
$creditCard = new AnetAPI\CreditCardType();
17+
$creditCard->setCardNumber("4111111111111111");
18+
$creditCard->setExpirationDate("1226");
19+
$creditCard->setCardCode("123");
20+
$paymentOne = new AnetAPI\PaymentType();
21+
$paymentOne->setCreditCard($creditCard);
22+
23+
$order = new AnetAPI\OrderType();
24+
$order->setDescription("New Item");
25+
26+
//create a transaction
27+
$transactionRequestType = new AnetAPI\HeldTransactionRequestType();
28+
$transactionRequestType->setAction("approve"); //other possible value: decline
29+
$transactionRequestType->setRefTransId("412121");
30+
31+
32+
$request = new AnetAPI\UpdateHeldTransactionRequest();
33+
$request->setMerchantAuthentication($merchantAuthentication);
34+
$request->setHeldTransactionRequest( $transactionRequestType);
35+
$controller = new AnetController\UpdateHeldTransactionController($request);
36+
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
37+
38+
39+
if ($response != null)
40+
{
41+
if($response->getMessages()->getResultCode() == 'Ok')
42+
{
43+
$tresponse = $response->getTransactionResponse();
44+
45+
if ($tresponse != null && $tresponse->getMessages() != null)
46+
{
47+
echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n";
48+
echo "Charge Credit Card AUTH CODE : " . $tresponse->getAuthCode() . "\n";
49+
echo "Charge Credit Card TRANS ID : " . $tresponse->getTransId() . "\n";
50+
echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n";
51+
echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n";
52+
}
53+
else
54+
{
55+
echo "Transaction Failed \n";
56+
if($tresponse->getErrors() != null)
57+
{
58+
echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n";
59+
echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n";
60+
}
61+
}
62+
}
63+
else
64+
{
65+
echo "Transaction Failed \n";
66+
$tresponse = $response->getTransactionResponse();
67+
if($tresponse != null && $tresponse->getErrors() != null)
68+
{
69+
echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n";
70+
echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n";
71+
}
72+
else
73+
{
74+
echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n";
75+
echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n";
76+
}
77+
}
78+
}
79+
else
80+
{
81+
echo "No response returned \n";
82+
}
83+
84+
return $response;
85+
}
86+
if(!defined('DONT_RUN_SAMPLES'))
87+
updateHeldTransaction();
88+
?>

RecurringBilling/create-subscription.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,9 @@ function createSubscription($intervalLength) {
3939

4040
$payment = new AnetAPI\PaymentType();
4141
$payment->setCreditCard($creditCard);
42+
4243
$subscription->setPayment($payment);
4344

44-
$order = new AnetAPI\OrderType();
45-
$order->setInvoiceNumber("1234354");
46-
$order->setDescription("Description of the subscription");
47-
$subscription->setOrder($order);
48-
4945
$billTo = new AnetAPI\NameAndAddressType();
5046
$billTo->setFirstName("John");
5147
$billTo->setLastName("Smith");

SampleCodeList.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,6 @@ UpdateSubscription,1,1
5252
CreateCustomerProfile,1,1
5353
CreateCustomerPaymentProfile,1,1
5454
ValidateCustomerPaymentProfile,1,0
55-
GetMerchantDetails,0,1
55+
GetMerchantDetails,0,1
56+
UpdateHeldTransaction,1,0
57+
GetHostedPaymentPage,0,1

TransactionReporting/get-merchant-details.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
define("AUTHORIZENET_LOG_FILE", "phplog");
77

88
function getMerchantDetails() {
9+
910
// Common Set Up for API Credentials
1011
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
1112
$merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID);
@@ -22,22 +23,27 @@ function getMerchantDetails() {
2223

2324
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok"))
2425
{
25-
echo "Merchant Name: " . $response->getMerchantName() . "\n";
26-
echo "Gateway ID: " . $response->getGatewayId() . "\n";
27-
echo "Processors: ";
28-
foreach ($response->getProcessors() as $processor)
29-
{
30-
echo $processor->getName() . "; ";
31-
}
32-
}
26+
echo "SUCCESS: Merchant Name:" . $response->getMerchantName() . "\n";
27+
echo " Gateway Id:" . $response->getGatewayId(). "\n";
28+
29+
foreach ($response->getProcessors() as $processor) {
30+
echo " ->Name : " . $processor->getName() . "\n";
31+
}
32+
33+
foreach ($response->getCurrencies() as $currency) {
34+
echo " ->Currency : " . $currency . "\n";
35+
}
36+
}
3337
else
3438
{
35-
echo "No response returned \n";
39+
echo "ERROR : Invalid response\n";
40+
$errorMessages = $response->getMessages()->getMessage();
41+
echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n";
3642
}
3743

3844
return $response;
3945
}
4046

4147
if(!defined('DONT_RUN_SAMPLES'))
4248
getMerchantDetails();
43-
?>
49+
?>

0 commit comments

Comments
 (0)