Authorize.net Get Response from Server Integration Method - php

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.

Related

2checkout.com payment method integration in 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.

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.

Paypal Express checkout NO PRICE

I've used paypal express checkout sandbox, but When I click to purchase something, doesn't show any price or item name in paypal.
On my page I've put this form :
<form action='expresscheckout.php' METHOD='POST'>
<input type='image' name='submit' src='https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif' border='0' align='top' alt='Check out with PayPal'/>
</form>
And I've included these two codes from paypal into my scripts:
https://www.paypal-labs.com/integrationwizard/ecpaypal/download.php?file=ecfile
https://www.paypal-labs.com/integrationwizard/ecpaypal/download.php?file=pplibfile
As I said, when I click on pay button , it takes me to the paypal sandbox, but with no price or item name. I even tried this with real API name and pass but still no price.
Meanwhile, I've also manually set the price in the expressscheckout.php :
$paymentAmount = $_SESSION["Payment_Amount"];
to
$paymentAmount = 32;
For Website Payments Standard :
I have put following two tags in my form tag :
<input type="hidden" name="item_name" value="<?php print $itemName; ?> "/>
<input type="hidden" id="amount" name="amount" value="<?php print $amount; ?>"/>

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

Save data upon PayPal checkout in

I am using CodeIgniter. My application goes like this,
user selects a topic from a dropdown
user is able to type some text/questions inside a text area under that dropdown
user clicks the PayPal checkout button and pay for asking a question
How will I save the id of the selected topic and the typed question if my submit button is calling PayPal's processing stuff and not my own CodeIgniter controller action thing?
Here's the code of the submit/checkout button of PayPal,
<form action=https://sandbox.paypal.com/cgi-bin/webscr method=post>
<input type=hidden name=cmd value=_cart>
<input type=hidden name=business value="test#gmail.com">
<input type=hidden name=item_name value="test">
<input type=hidden name=item_number value="1">
<input type=hidden name=amount value="<?php foreach($query3->result() as $row){echo $row->price; } ?>">
<input type=hidden name=quantity value="1" disabled="disabled">
<input type=hidden name=currency_code value="USD">
<input type="hidden" name="return" value="http://your-website.com/after-payment-page.html" / >
<input type=image id="checkout" src="https://www.paypal.com/images/x-click-but6.gif" Border="0" name=submit><br>
<input type=hidden name=add value=1></form>
I split the pages into two parts instead
You can use notify_url
The URL to which PayPal posts
information about the transaction, in
the form of Instant Payment
Notification messages
Example:
<input name="notify_url" value="http://yourdomain.com/controller/method" type="hidden">
The example above receives some $_POST variables from PayPal when the payment is completed, even if the customer never returns to your website.
You can save the topic, question and any other information that gets passed in the above method.
You can attach another event to the submit button
For example:
$("#checkout").click(function() {
saveTheParmYouNeed();
});

Categories