cancel
Showing results for 
Search instead for 
Did you mean: 

Charging Card using CIM

Hey all,

 

I'm having issues charging a credit using the CIM customer profile ID and payment ID. I looked at the example in the API reference, but I'm not seeing a place to put the profile ID and payment ID after the account is already created. I put the code sample below, but the code seems to be pulling the payment information from the information used to create the CIM profile. Any advice would be greatly appreciated!

 

// Create additional payment data and add a new credit card
$creditCard = new AnetAPI\CreditCardType();
$creditCard->setCardNumber( "4007000000027" );
$creditCard->setExpirationDate( "2038-12");
$paymentTwo = new AnetAPI\PaymentType();
$paymentTwo->setCreditCard($creditCard);

$request = new AnetAPI\CreateCustomerPaymentProfileRequest();
$request->setMerchantAuthentication($merchantAuthentication);
$request->setRefId( $refId);
$request->setCustomerProfileId($customerProfileId);

$paymentprofile2 = new AnetAPI\CustomerPaymentProfileType();
$paymentprofile2->setCustomerType('business');
$paymentprofile2->setBillTo($billto);
$paymentprofile2->setPayment($paymentTwo);
$paymentprofiles2[] = $paymentprofile2;

$request->setPaymentProfile($paymentprofile2);
$controller = new AnetController\CreateCustomerPaymentProfileController($request);
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") )
{
echo "CreateCustomerPaymentProfileRequest SUCCESS: PROFILE ID : " . $response->getCustomerPaymentProfileId() . "\n";
$customerProfileId = $response->getCustomerPaymentProfileId();
}
else
{
echo "CreateCustomerPaymentProfileRequest ERROR : Invalid response\n";
}

$transactionRequestType = new AnetAPI\TransactionRequestType();
$transactionRequestType->setTransactionType( "authCaptureTransaction");
$transactionRequestType->setAmount(100.50);
$transactionRequestType->setPayment($paymentprofile2->getPayment());
$transactionRequestType->setOrder($order);
$transactionRequestType->addToLineItems($lineitem);
$transactionRequestType->setTax($tax);
//$transactionRequestType->setPoNumber($ponumber);
//$transactionRequestType->setCustomer($customer);
$transactionRequestType->setBillTo($billto);
$transactionRequestType->setShipTo($shipto);
$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);
if ($response != null)
{
$tresponse = $response->getTransactionResponse();
if (($tresponse != null) && ($tresponse->getResponseCode()=="1") )
{
echo "Charge Customer Profile APPROVED :" . "\n";
echo " Charge Customer Profile AUTH CODE : " . $tresponse->getAuthCode() . "\n";
echo " Charge Customer Profile TRANS ID : " . $tresponse->getTransId() . "\n";
}
elseif (($tresponse != null) && ($tresponse->getResponseCode()=="2") )
{
echo "ERROR" . "\n";
}
elseif (($tresponse != null) && ($tresponse->getResponseCode()=="4") )
{
echo "ERROR: HELD FOR REVIEW:" . "\n";
}
}

NewToThis
Member
1 REPLY 1

So I found the solution and in case anyone else needs it, I put the relevant parts below.

 

$paymentProfile = new AnetAPI\PaymentProfileType();
$paymentProfile->setPaymentProfileId("");

$profile = new AnetAPI\CustomerProfilePaymentType();
$profile->setCustomerProfileId("");
$profile->setPaymentProfile($paymentProfile);

 

$transactionRequestType = new AnetAPI\TransactionRequestType();
$transactionRequestType->setTransactionType( "authCaptureTransaction");
$transactionRequestType->setProfile($profile);

NewToThis
Member