Jump to content

Recommended Posts

I'm stumped on this one.

 

I have a page of code to run credit card transactions. It originally echoed out on the same page. But someone was refreshing the page and recharging and/or resending info to the database. So I now have it redirecting to a new page via header. Clears out the data, does exactly what I want.

 

Then I ran into the problem of failed transactions. That lands them on this page. And it prints out the error on the processing page and nothing else. eek! Is it possible to set a redirect to an error page within the die()? I could put content within this area, but it would create the error in the 'successful' header redirect. Is there a way to do a header redirect within this code for a failed transaction and not lose the data in case they want to hit the back button and make a correction?

 

UPDATE: I can add a header redirect to the die() but how to get the errorstack to that page? grr.

 

if (!$aim->setCard($nameoncard, $_REQUEST['ccnumber'], $_REQUEST['expmonth'], $_REQUEST['expyear'], $_REQUEST['cc_code']))
die("The credit card is invalid: " . print_r($aim->errorStack, 1));

// Sets the customer's billing information
$aim->setBuyer($_REQUEST['fname'], $_REQUEST['lname'], $_REQUEST['address'], $_REQUEST['city'], $_REQUEST['state'], $_REQUEST['zip'], $_REQUEST['email'], $_REQUEST['phone']);

// Attempt to process the card and set $approval to the approval code
if (!$approval = $aim->processCard("Workshops for Youth", $final_total)){
echo "<br><strong><h3><font color=#F63026> Oops!</font></h3></strong><br> There was an error proccessing the credit card! <br> Please <a href='registration.php'>return to the registration page</a> to try again, or <br>contact us to register over the phone at <b>480-245-9724</b><br> <br>" . print_r($aim->errorStack,1);
$appcodedesc = "Error processing credit card.";
$approval = 0;
}else{
// If we made it this far, the card was successfully charged
       // there's a bunch of code to input to database and then a header snippet to redirect the user to a 'finished' page.

Link to comment
https://forums.phpfreaks.com/topic/259567-code-within-die/
Share on other sites

die() means exactly what it says... It will display a message and die.

 

If you want to display a message and want user to perform some action, instead of die you can redirect the user to some other page and show message on that page.

 

I would advise against use of back button or resubmit for a page that has Credit card transactions even if it is a failed one...

 

 

Link to comment
https://forums.phpfreaks.com/topic/259567-code-within-die/#findComment-1330610
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.