cancel
Showing results for 
Search instead for 
Did you mean: 

Who Me Too'd this topic

Adding a new line item - SDK - PHP

I'm having a hard time adding a new line item using the SDK (PHP). An error gets generated.

 

 

 

<?php

require 'apps/authorizenet/sdk/vendor/autoload.php';

use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;

define("AUTHORIZENET_LOG_FILE","phplog");

// Common setup for API credentials
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName("********");
$merchantAuthentication->setTransactionKey("**************");
$refId = 'ref' . time();

// Create the payment data for a credit card
$creditCard = new AnetAPI\CreditCardType();
$creditCard->setCardNumber("4111111111111111");
$creditCard->setExpirationDate( "2038-12");
$creditCard->setCardCode("513");
$paymentCreditCard = new AnetAPI\PaymentType();
$paymentCreditCard->setCreditCard($creditCard);

// Create the Bill To info
$billto = new AnetAPI\CustomerAddressType();
$billto->setFirstName("Ellen");
$billto->setLastName("Johnson");
$billto->setCompany("Souveniropolis");
$billto->setAddress("14 Main Street");
$billto->setCity("Pecan Springs");
$billto->setState("TX");
$billto->setZip("44628");
$billto->setCountry("USA");
$billto->setPhoneNumber("310-867-5309");
//$billto->setEmail("chingone@wtf.com");

 

// LineItem - NOT WORKING
$lineItem = new AnetAPI\LineItemType();
$lineItem->setItemId("123");
$lineItem->setName("Donation");
$lineItem->setDescription("Ellen Johnson donated $50.00");
$lineItem_Array[] = $lineItem;

 

// Create a transaction
$transactionRequestType = new AnetAPI\TransactionRequestType();
$transactionRequestType->setTransactionType("authCaptureTransaction");
$transactionRequestType->setAmount(187.66);
$transactionRequestType->setBillTo($billto);
$transactionRequestType->setPayment($paymentCreditCard);
$transactionRequestType->setLineItems($lineItem_Array);

$request = new AnetAPI\CreateTransactionRequest();
$request->setMerchantAuthentication($merchantAuthentication);
$request->setRefId( $refId);
$request->setTransactionRequest($transactionRequestType);
$controller = new AnetController\CreateTransactionController($request);
$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
//$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::PRODUCTION);

if ($response != null)
{
$tresponse = $response->getTransactionResponse();
if (($tresponse != null) && ($tresponse->getResponseCode()=="1"))
{
echo "Charge Credit Card AUTH CODE : " . $tresponse->getAuthCode() . "\n";
echo "Charge Credit Card TRANS ID : " . $tresponse->getTransId() . "\n";
}
else
{
echo "Charge Credit Card ERROR : Invalid response :\n";
}
}
else
{
echo "Charge Credit Card Null response returned";
}
?>

 

 

Any help is appriciated.

Bandsaw000o0
Member
Who Me Too'd this topic