jussc Posted November 10, 2016 Share Posted November 10, 2016 (edited) <?php if(isset($_POST['amount'])) { $company = $_POST["company"]; $invoice = $_POST["invoice"]; $subject = "New Payment"; $recipient = "my@email.com"; $message = "Message from $company with Invoice # $invoice"; mail($recipient, $subject, $message); // *********** Payment $x_amount = $_POST['amount']; $x_login = "don't post sensitive information"; // Take from Payment Page ID in Payment Pages interface $transaction_key = "on a public forum"; // Take from Payment Pages configuration interface $x_currency_code = "CAD"; // Needs to agree with the currency of the payment page srand(time()); // initialize random generator for x_fp_sequence $x_fp_sequence = rand(1000, 100000) + 123456; $x_fp_timestamp = time(); // needs to be in UTC. Make sure webserver produces UTC // The values that contribute to x_fp_hash $hmac_data = $x_login . "^" . $x_fp_sequence . "^" . $x_fp_timestamp . "^" . $x_amount . "^" . $x_currency_code; $x_fp_hash = hash_hmac('MD5', $hmac_data, $transaction_key); $values = array('login' => $x_login, 'amount' => $x_amount, 'sequence' => $x_fp_sequence, 'timestamp' => $x_fp_timestamp, 'hash' => $x_fp_hash, 'currency' => $x_currency_code, 'company' => $company); echo json_encode($values); die; } ?> Hello, I am having a bit of trouble in setting up a payment page. I am trying to do two things here. The form has three fields - Company, Invoice, and Amount. When the submit button is clicked, the action should take me to a payment page. This part works great. However, I am trying to _POST the other two fields - Company and Invoice - so I can have this information emailed to myself once the client clicks "pay". RIght now, when the button is clicked, it sends me to the payment page (good), and then the email also gets sent (which is also good). However, the email message doesn't work - it only shows the text without the variables. Like: Message from with Invoice # Without either variable posting through Is something like this possible? Or am I doing it completely wrong? Any help would be appreciated! Justin Edited November 10, 2016 by requinix Quote Link to comment Share on other sites More sharing options...
requinix Posted November 10, 2016 Share Posted November 10, 2016 What's the code that POSTs the data to this page? Because that's where the problem is. Quote Link to comment Share on other sites More sharing options...
jussc Posted November 10, 2016 Author Share Posted November 10, 2016 Thanks for the response so far! This is the HTML. This is why I am confused - I am not sure whether it is possible because the target is the payment page... <form action="https://rpm.demo.e-xact.com/payment" method="POST" id="payment" onsubmit="return prepareForm();"> <input type="hidden" name="x_show_form" value="PAYMENT_FORM"/> <input type="hidden" name="x_test_request" value="FALSE"/> <input name="x_login" id="x_login" type="hidden" value=""> <input name="x_amount" id="x_amount" type="hidden" value=""> <input name="x_fp_sequence" id="x_fp_sequence" type="hidden" value=""> <input name="x_fp_timestamp" id="x_fp_timestamp" type="hidden" value=""> <input name="x_fp_hash" id="x_fp_hash" type="hidden" value="" size="50"> <input name="x_currency_code" id="x_currency_code" type="hidden" value=""> <div class="form-group"> <label for="company">Company Name:</label> <input type="text" class="form-control input-lg half" name="company" placeholder=""> </div> <div class="form-group"> <label for="invoice">Invoice #:</label> <input type="text" class="form-control input-lg half" name="invoice" placeholder="A12345"> </div> <div class="form-group"> <label for="amount">Amount:</label> <input type="text" class="form-control input-lg half" name="x_my_amount" placeholder="123.45" id="x_my_amount"> </div> <input type="submit" class="btn btn-default" name="submit" id="submitPayment" value="Pay with Hosted Checkout" /> </form> Quote Link to comment Share on other sites More sharing options...
requinix Posted November 10, 2016 Share Posted November 10, 2016 It looks like you're using Javascript (that "prepareForm" bit) to process the form before it gets submitted. That's how the data is being passed to your PHP. So. What's the code for prepareForm? When it constructs the AJAX request to send to your code, does it include the new fields you added? Quote Link to comment Share on other sites More sharing options...
jussc Posted November 10, 2016 Author Share Posted November 10, 2016 here is the function prepareForm function prepareForm(){ $('#submitPayment').val('Please wait ...'); var processPayment = $.ajax({ type: 'POST', url: "test.php", data: {"amount": $('#x_my_amount').val()}, dataType: 'json', async: false, success: function(data) { $('#x_login').val(data.login); $('#x_amount').val(data.amount); $('#x_fp_sequence').val(data.sequence); $('#x_fp_timestamp').val(data.timestamp); $('#x_fp_hash').val(data.hash); $('#x_currency_code').val(data.currency); if(data.hash){ makeProcessed(true); } } }); return processed; }; i am so glad you can explain this to me in plain english i really appreciate it. so would the trick be to input in the fields that i have in the HTML as modeled in the function above? thanks Quote Link to comment Share on other sites More sharing options...
Solution Jacques1 Posted November 10, 2016 Solution Share Posted November 10, 2016 Let's look at this line: data: {"amount": $('#x_my_amount').val()}, This is what gets sent to the server. I'm sure you can figure out the rest. Quote Link to comment Share on other sites More sharing options...
requinix Posted November 10, 2016 Share Posted November 10, 2016 You can make things easier on yourself by just sending the entire .serialize()d form instead of picking and choosing which fields to include. If you do, make sure to update your PHP because the amount will be called "x_my_amount". Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted November 10, 2016 Share Posted November 10, 2016 There are plenty of input fields which are obviously not meant to be sent. I'd be careful with that. Quote Link to comment Share on other sites More sharing options...
requinix Posted November 10, 2016 Share Posted November 10, 2016 Fair point. Then instead $("#payment input:not(:hidden)").serialize() 1 Quote Link to comment Share on other sites More sharing options...
jussc Posted November 12, 2016 Author Share Posted November 12, 2016 It worked! Thank you to the both of you for helping me out on this. I really appreciate this. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.