Reply
Highlighted
Contributor
Posts: 10
Registered: ‎04-30-2013

Submit Multiple Transactions on One Page

Hi,

 

I am trying to create an application that would allow more than one customer to contribute to the total cost of the purchase by enabling them to designate how much of the total purchase price they would like to pay at check out.  You can see a simple example here:

 

http://www.splitsum.com/samples/your_store/2cards.php

 

I am usng the Advanced Integration Method and have the page submitting to the following script.  Unfrotunately, it only processes the second credit card's order and does not process the first card at all.  Would anyone be able to explain to me what I am doing wrong?  Any help would be greatly appreciated.  Thanks so much!

 

<?php

require_once 'coffee_store_settings.php';

if ($METHOD_TO_USE == "AIM") {
$transaction = new AuthorizeNetAIM;
$transaction->setSandbox(AUTHORIZENET_SANDBOX);
$transaction->setFields(
array(
'amount' => $_POST['amount'],
'card_num' => $_POST['x_card_num'],
'exp_date' => $_POST['x_exp_date'],
'first_name' => $_POST['x_first_name'],
'last_name' => $_POST['x_last_name'],
'address' => $_POST['x_address'],
'city' => $_POST['x_city'],
'state' => $_POST['x_state'],
'country' => $_POST['x_country'],
'zip' => $_POST['x_zip'],
'email' => $_POST['x_email'],
'card_code' => $_POST['x_card_code'],
)
);
$response = $transaction->authorizeAndCapture();
if ($response->approved) {
$transaction = new AuthorizeNetAIM;
$transaction->setSandbox(AUTHORIZENET_SANDBOX);
$transaction->setFields(
array(
'amount' => $_POST['amount'],
'card_num' => $_POST['x_card_num'],
'exp_date' => $_POST['x_exp_date'],
'first_name' => $_POST['x_first_name'],
'last_name' => $_POST['x_last_name'],
'address' => $_POST['x_address'],
'city' => $_POST['x_city'],
'state' => $_POST['x_state'],
'country' => $_POST['x_country'],
'zip' => $_POST['x_zip'],
'email' => $_POST['x_email'],
'card_code' => $_POST['x_card_code'],
)
);
$response = $transaction->authorizeAndCapture();

} elseif (count($_POST)) {
$response = new AuthorizeNetSIM;
if ($response->isAuthorizeNet()) {
if ($response->approved) {
// Transaction approved! Do your logic here.
// Redirect the user back to your site.
$return_url = $site_root . 'thank_you_page.php?transaction_id=' .$response->transaction_id;
} else {
// There was a problem. Do your logic here.
// Redirect the user back to your site.
$return_url = $site_root . 'error_page.php?response_reason_code='.$response->response_reason_code.'&response_code='.$response->response_code.'&response_reason_text=' .$response->response_reason_text;
}
echo AuthorizeNetDPM::getRelayResponseSnippet($return_url);
} else {
echo "MD5 Hash failed. Check to make sure your MD5 Setting matches the one in config.php";
}
} }

Highlighted
Expert
Posts: 4,525
Registered: ‎03-08-2010

Re: Submit Multiple Transactions on One Page

because the input fields name is the same

Highlighted
Contributor
Posts: 10
Registered: ‎04-30-2013

Re: Submit Multiple Transactions on One Page

I tried to rename the fields but it did nto work because the variable names need to all be the same in order for them to be processed by the authorized.net server.  If I try to submit something like $amount2, it is rejected.  Anyone have any idea as to how to work around it?

Highlighted
Contributor
Posts: 13
Registered: ‎07-25-2012

Re: Submit Multiple Transactions on One Page

You'll have to create code that maps the new form fields names for the second transaction to the appropriate authorize.net keys before you use that second part of the form to create your second transaction.

Highlighted
Contributor
Posts: 13
Registered: ‎07-25-2012

Re: Submit Multiple Transactions on One Page

such as

array(
'amount' => $_POST['amount2'],
'card_num' => $_POST['x_card_num2'],
'exp_date' => $_POST['x_exp_date2'],
'first_name' => $_POST['x_first_name2'],
'last_name' => $_POST['x_last_name2'],
'address' => $_POST['x_address2'],
'city' => $_POST['x_city'2],
'state' => $_POST['x_state2'],
'country' => $_POST['x_country2'],
'zip' => $_POST['x_zip2'],
'email' => $_POST['x_email2'],
'card_code' => $_POST['x_card_code2'],
)

Highlighted
Contributor
Posts: 10
Registered: ‎04-30-2013

Re: Submit Multiple Transactions on One Page

Thanks @shkkmo!