2checkout.com payment method integration in PHP - php

Can any one help me with 2checkout.com payment method integration in PHP step wise? I have written a form as it is described in documentation of 2checkout.com site for inline process. After submitting the form it shows that the payment is successful but I didn't receive any IPN result in my function. So hence it is proved that payment is not done.
I will be grateful if anyone helps me with this. sample code is listed below. What I have to do next after that to get exact response from 2checkout so that I can understand the payment has been successful.
<form id="2checkout" action='https://sandbox.2checkout.com/checkout/purchase' method='post'>
<input type='hidden' name='sid' value='111111111' />
<input type='hidden' name='mode' value='2CO' />
<input type='hidden' name='li_0_type' value='product' />
<input type='hidden' name='li_0_name' value='test title' />
<input type='hidden' name='li_0_price' value='212.00' />
<input type='hidden' name='x_receipt_link_url' value='http://myserver.com/ipn_twocheckout' />
<input type='hidden' name='card_holder_name' value='Joe Flagster' />
<input type='hidden' name='street_address' value='123 Main Street' />
<input type='hidden' name='street_address2' value='Suite 200' />
<input type='hidden' name='city' value='Townsville' />
<input type='hidden' name='state' value='Ohio' />
<input type='hidden' name='zip' value='43206' />
<input type='hidden' name='country' value='USA' />
<input type='hidden' name='email' value='mysample#gmail.com' />
<input type='hidden' name='phone' value='614-921-2450' />
</form>
<script type="text/javascript">document.getElementById('2checkout').submit();</script>
<script src="https://www.2checkout.com/static/checkout/javascript/direct.min.js"></script>

The easiest way to verify that a payment was successful is to simply validate it on the return, here's an example of a return validation, assuming that you are returning to this page after the purchase is complete at 2Checkout:
<?php
$hashSecretWord = 'tango'; //2Checkout Secret Word
$hashSid = 111111111; //2Checkout account number
$hashTotal = '212.00'; //Sale total to validate against
$hashOrder = $_REQUEST['order_number']; //2Checkout Order Number
$StringToHash = strtoupper(md5($hashSecretWord . $hashSid . $hashOrder . $hashTotal));
if ($StringToHash != $_REQUEST['key']) {
$result = 'Fail - Hash Mismatch';
} else {
$result = 'Success - Hash Matched';
}
echo $result;

simple problem:
your submitting payment in sandbox mode.
(https://sandbox.2checkout.com/checkout/purchase)
in this case "x_receipt_link_url" parameter will not work.
(it will only work for live account).
to test the response in your project.
login to your sandbox account. then navigate to
(please find the below attachments for clear idea)
Account tab=>site management tab.
then select the radio button Header Redirect.
then
Enter the approved url and affiliate url as : http://myserver.com/ipn_twocheckout (your site url to receive success callback and handling).
then save changes.
i hope this answer will help you.

Related

How to create QR Code for each register user?

I would like my user after register an account on my website and have their own unique QR code. The QR code will only contain the member serial number and for us to scan whether the user is truly our member. So may I ask everyone how am I going to achieve that and with what? My entire website is using PHP to write.
This is the code to generate qr code in php
<body onload="loadGraph()">
<form action='https://chart.googleapis.com/chart' method='POST' id='post_form' onsubmit="this.action = 'https://chart.googleapis.com/chart?chid=' + (new Date()).getMilliseconds();
return true;"> <input type='hidden' name='cht' value='qr' />
<input type='hidden' name='cht' value='qr' />
<input type='hidden' name='chs' value='300x300' />
<input type='hidden' name='chl' value='This is your QR code. You need to pass the users serial number here '/>
<input type='submit' value="Download your Qr code Here" />
</form>
change the code accordingly for your requirement.

Two Forms, One Button. Not sure of how to make this happen

I have a page that prints out rows of information. In each row is a notes box:
<?php
<td style='font-size:12px;width:300px;'>
{$row['Notes']} <br /><center><br />
<form action=\"http://********/functions/notes.php\" id='formNotesform' method='post'>
<input type='hidden' id='ID' name='ID' value='{$row['ID']}' />
<textarea placeholder=\"Add more notes here...\" name=\"notes\" rows=\"5\" cols=\"30\"'></textarea><br />
<input type='submit' name='formNotes' id='formNotes' value='Add to Notes' />
</form>
</center></td>
?>
Then there's also another button on the page in each row.
<form action=\"http://********/functions/archive.php\" method='post' id='formArchiveform' onclick=\"return checkArchive()\">
<input type='hidden' id='ID' name='ID' value='{$row['ID']}' />
<input type='submit' name='formArchive' id='formArchive' value='Archive' style=\"height:25px; width:80px\"/>
</form>
What I need to happen is that when someone clicks the "Add to Notes" button it does its job but when someone clicks the "archive" button it checks to see if notes is empty and if not then it submits that as well (kind of like a failsafe).
Ideally I'd like to just pick up the Notes data and post it to the archived.php file the form is going to anyways since that would cause minimal disruption to the code base but I can't get it to work.
I understand this isn't really a sensible choice. It just has to be done. Thanks for the help!
If I had reputation I would ask first because what I understood is that you want to now what button has been pressed to then do another things.
If that's it do this:
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
if(isset($_POST['formNotes']))
{
//...
}
elseif(isset($_POST['formArchive']))
{
//...
}
}

paypal sandbox testing doesn't return automatic and payment failed error

My testing here http://evasoft.in/paypal/products.php. I am new in paypal, i am try to setup paypal payment via my website and return collect buyer's information like transaction id, date etc. But i got payment failed error and i doesn't get any value from paypal. I WANT AUTOMATIC REDIRECT AFTER SUCCESS.
My product page's code
<form action='<?php echo $paypal_url; ?>' method='post' name='frmPayPal1'>
<input type='hidden' name='business' value='<?php echo $paypal_id;?>'>
<input type='hidden' name='cmd' value='_xclick'>
<input type='hidden' name='item_name' value='<?php echo $row['product'];?>'>
<input type='hidden' name='item_number' value='<?php echo $row['pid'];?>'>
<input type='hidden' name='amount' value='<?php echo $row['price'];?>'>
<input type='hidden' name='no_shipping' value='1'>
<input type='hidden' name='currency_code' value='USD'>
<input type='hidden' name='handling' value='0'>
<input type='hidden' name='cancel_return' value='http://evasoft.in/paypal/cancel.php'>
<input type='hidden' name='return' value='http://evasoft.in/paypal/success.php'>
<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
My Sucess.php page code here
<?php
require 'db_config.php';
$item_no = $_GET['item_number'];
$item_transaction = $_GET['tx'];
$item_price = $_GET['amt'];
$item_currency = $_GET['cc'];
//Getting product details
$sql=mysql_query("select product,price,currency from products where pid='$item_no'");
$row=mysql_fetch_array($sql);
$price=$row['price'];
$currency=$row['currency'];
//Rechecking the product details
if($item_price==$price && item_currency==$currency)
{
$result = mysql_query("INSERT INTO sales(pid, uid, saledate,transactionid) VALUES('$item_no', '$uid', NOW(),'$item_transaction')");
if($result){
echo "<h1>Welcome, $username</h1>";
echo '<h1>Payment Successful</h1>';
echo "<b>Example Query</b>: INSERT INTO sales(pid, uid, saledate) VALUES('<font color='#f00;'>$item_no</font>', '<font color='#f00;'>$uid</font>', <font color='#f00;'>NOW()</font>)";
}else{
echo "Payment Error";
}
}
else
{
echo "Payment Failed";
}
?>
I have done a test checkout on your website and could see that Auto Return feature is turned off on your sandbox account.
Auto Return is turned off by default.
1.To turn on Auto Return
2.Log in to your PayPal account at https://www.paypal.com.
3.The My Account Overview page appears.
4.Click the Profile subtab.
5.The Profile Summary page appears. Under the Selling Preferences column, click the Website Payment
Preferences link.
6.The Website Payment Preferences page appears, as shown below.
7.Under Auto Return for Website Payments, click the On radio button to enable Auto Return.
8.In the Return URL field, enter the URL to which you want your payers redirected after they complete their payments.
Also, note that Auto Return Feature will not work if the Payment is made with Debit or credit card. You need to manually click in "return" link to get re-directed to your return URL.

Authorize.net Get Response from Server Integration Method

Suppose I have an Authorize.net form opened a pop-up of this form:
<?php
$api_login_id = 'YOUR_API_LOGIN_ID';
$transaction_key = 'YOUR_TRANSACTION_KEY';
$amount = "5.99";
$fp_timestamp = time();
$fp_sequence = "123" . time(); // Can be changed to an invoice or other unique number.
$fingerprint = AuthorizeNetSIM_Form::getFingerprint($api_login_id, $transaction_key,
$amount, $fp_sequence, $fp_timestamp);
?>
<form method='post' action="https://test.authorize.net/gateway/transact.dll">
<input type='hidden' name="x_login" value="<?php echo $api_login_id?>" />
<input type='hidden' name="x_fp_hash" value="<?php echo $fingerprint?>" />
<input type='hidden' name="x_amount" value="<?php echo $amount?>" />
<input type='hidden' name="x_fp_timestamp" value="<?php echo $fp_timestamp?>" />
<input type='hidden' name="x_fp_sequence" value="<?php echo $fp_sequence?>" />
<input type='hidden' name="x_version" value="3.1" />
<input type='hidden' name="x_show_form" value="payment_form" />
<input type='hidden' name="x_test_request" value="false" />
<input type='hidden' name="x_method" value="cc" />
<input type='submit' value="Click here for the secure payment form" />
</form>
After customer has completed the form, and the payment is complete, how do i get the response from the form so I could check if payment is complete? Something like:
if ($response->approved) {
echo "Success! Transaction ID:" . $response->transaction_id;
} else {
echo "ERROR:" . $response->error_message;
}
You need to either use Relay Response
Relay Response is a feature available to merchants using Server Integration Method (SIM) or Simple Checkout. It instructs the payment gateway to return transaction results to the merchant using an HTML form POST to a specified URL on the merchant's Web server. A script or program at the URL can be used to create a custom receipt page using the transaction information. The custom receipt page is then relayed back to the customer's browser. Relay Response does not redirect the end user back to the merchant’s server, but relays the page content to the end user instead of displaying the Authorize.Net default receipt page.
or Silent Post.
Silent Post is an Authorize.Net feature that POSTs transaction data to a URL whenever a transaction is processed by them. It happens behind the scenes and allows a system to automate the handling of approved and declined transactions
I am the author of the Silent Post article as well as instructions for how to implement it in PHP.

Redirection to the original site after purchase is completed in Paypal

I'm making one web app. I've integrated Paypal in it using simple form submission to the Paypal site. Everything works well. but whenever the payment gets successful it should redirect back to my original site with the response from Paypal. However, it's not working as it should be. Currently it stays on the Paypal site only.
<form action='https://www.sandbox.paypal.com/cgi-bin/webscr' method='post' name='form'>
<input type='hidden' name='business' value='<?php echo $paypal_id; ?>'>
<input type='hidden' name='cmd' value='_xclick'>
<input type='hidden' name='item_name' id='item_name' value=''>
<input type='hidden' name='item_number' id='item_number' value=''>
<input type='hidden' name='amount' id='amount' value=''>
<input type='hidden' name='no_shipping' value='1'>
<input type='hidden' name='currency_code' value='USD'>
<input type='hidden' name='cancel_return' value='http://yoursite.com/cancel.php'>
<input type='hidden' name='return' value='http://mysite.com/user_credits/purchase_credits'>
<input type="image" src="https://paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" name="submit">
what am I missing in it? I'm using CakePHP 2.0.
You have to enable auto return functionality setting in paypal .
Just follow the below steps to enable
Log in and click the Profile subtab under My Account.
Click the Website Payment Preferences link under Selling Preferences.
Click the On radio button to enable Auto Return.
Enter the Return URL. Note: You must meet the Return URL requirements in order to set up Auto Return. Learn more about Return URL.
For sandbox account do the following
Log in to the Sandbox Merchant Id and click the Profile subtab under My Account.
Click the More Option link under Profile.
Look Selling Preferences which is third row.
Click the Website Payment Preferences link under Selling Preferences
Click the On radio button to enable Auto Return.
Click the On radio button to enable Auto Return.
Enter the Return URL. Note: You must meet the Return URL requirements in order to set up Auto Return. Learn more about Return URL.
According to the spec for PayPal button parameters, you need to set the return method.
<input type='hidden' name='return' value='http://mysite.com/user_credits/purchase_credits'>
<input type='hidden' name='rm' value='1'>
The values are as follows:
0 - Don't redirect, and use GET.
1 - Automatically redirect to the return URL using GET.
2 - Automatically redirect to the return URL using POST, including all payment variables.
For implement PayPal button html form parameters, use this
<form method=post action=https://api-3t.sandbox.paypal.com/nvp>
<input type=hidden name=USER value=API_username>
<input type=hidden name=PWD value=API_password>
<input type=hidden name=SIGNATURE value=API_signature>
<input type=hidden name=VERSION value=XX.0>
<input type=hidden name=PAYMENTREQUEST_0_PAYMENTACTION value=Sale>
<input name=PAYMENTREQUEST_0_AMT value=19.95>
<input type=hidden name=RETURNURL value=https://www.YourReturnURL.com>
<input type=hidden name=CANCELURL value=https://www.YourCancelURL.com>
<input type=submit name=METHOD value=SetExpressCheckout>
</form>
This page contains all the information you need
https://developer.paypal.com/docs/classic/express-checkout/integration-guide/ECGettingStarted/
Or use the integration wizard to generate de form
https://devtools-paypal.com/integrationwizard/ecpaypal/main.php

Categories