PayPal PDT works in sandbox but not live - paypal

I am trying to add a Paypal Payments button onto our website. I have Auto Return and Payment Data Transfer turned on.
When I point to sandbox, everything works correctly and it returns to my website with the transaction id in the url.
When I point to production PayPal, no transaction id is returned. Payment does go through.
Here is the form code:
<form action="#VARIABLES.strHostAddress#" method="post" target="_top" id="testform">
<input type="hidden" name="cmd" value="_donations">
<input type="hidden" name="business" value="#VARIABLES.strBusinessEmail#">
<input type="hidden" name="item_name" value="#VARIABLES.strGiftDesignation# - #VARIABLES.strGiftDesignation2#">
<input type="hidden" name="amount" value="#VARIABLES.intPayAmt#">
<input type="hidden" name="first_name" value="#VARIABLES.strFirstName#">
<input type="hidden" name="last_name" value="#VARIABLES.strLastName#">
<input type="hidden" name="address1" value="#VARIABLES.strLine1#">
<input type="hidden" name="address2" value="#VARIABLES.strLine2#">
<input type="hidden" name="city" value="#VARIABLES.strCity#">
<input type="hidden" name="state" value="#VARIABLES.strState#">
<input type="hidden" name="zip" value="#VARIABLES.strPostalCode#">
<input type="hidden" name="email" value="#VARIABLES.strEmail#">
<input type="hidden" name="cancel_return" value="#VARIABLES.strCancelPage#">
<input type="hidden" name="return" value="#VARIABLES.strThankYouPage#">
<input type="hidden" name="rm" value="2">
</form>
where #VARIABLES.strHostAddress# is "https://www.paypal.com/cgi-bin/webscr" for live or "https://www.sandbox.paypal.com/cgi-bin/webscr" for sandbox.
Any suggestions or idea why this would happen?

I am including a step by step explanation that PayPal has on their developers website and the important part is that you get the "tx" value, and send it back with the PDT "Identity Token" which you can find on the PayPal account when you login to configure PDT.
The following steps illustrate the basic flow of a PDT transaction.
"A customer submits a payment.
PayPal sends the transaction ID of the payment through HTTP as a GET variable (tx). This information is sent to the Return URL you specified in your PayPal account profile.
Your return URL web page contains an HTML POST form that retrieves the transaction ID and sends the transaction ID and your unique PDT token to PayPal.
PayPal replies with a message indicating SUCCESS or FAIL. The SUCCESS message includes transaction details, one per line, in the = format. This key-value pair string is URL encoded."
Ok, I just found this GitHub link that gives various code versions of how to get the "tx" and use it and the Identity Key to get all the name value pairs and parse them. It has an example in each language. Just click on the file name.
// ASP .NET C#
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Web;
using System.Collections.Generic;
public partial class csPDTSample : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// CUSTOMIZE THIS: This is the seller's Payment Data Transfer authorization token.
// Replace this with the PDT token in "Website Payment Preferences" under your account.
string authToken = "Dc7P6f0ZadXW-U1X8oxf8_vUK09EHBMD7_53IiTT-CfTpfzkN0nipFKUPYy";
string txToken = Request.QueryString["tx"];
string query = "cmd=_notify-synch&tx=" + txToken + "&at=" + authToken;
//Post back to either sandbox or live
string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr";
string strLive = "https://www.paypal.com/cgi-bin/webscr";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strSandbox);
//Set values for the request back
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = query.Length;
//Send the request to PayPal and get the response
StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
streamOut.Write(query);
streamOut.Close();
StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
string strResponse = streamIn.ReadToEnd();
streamIn.Close();
Dictionary<string,string> results = new Dictionary<string,string>();
if(strResponse != "")
{
StringReader reader = new StringReader(strResponse);
string line=reader.ReadLine();
if(line == "SUCCESS")
{
while ((line = reader.ReadLine()) != null)
{
results.Add(line.Split('=')[0], line.Split('=')[1]);
}
Response.Write("<p><h3>Your order has been received.</h3></p>");
Response.Write("<b>Details</b><br>");
Response.Write("<li>Name: " + results["first_name"] + " " + results["last_name"] + "</li>");
Response.Write("<li>Item: " + results["item_name"] + "</li>");
Response.Write("<li>Amount: " + results["payment_gross"] + "</li>");
Response.Write("<hr>");
}
else if(line == "FAIL")
{
// Log for manual investigation
Response.Write("Unable to retrive transaction detail");
}
}
else
{
//unknown error
Response.Write("ERROR");
}
}
}
PDT-Code-Samples on GitHub

Related

Adding a custom field in Paypal checkout

We are using Paypal checkout for our web app. We have the client lib where we are setting up the payment. In the back end, we are trying to capture the processed details via webhook. We tested this on a sandbox account. The webhook is sending all the details as expected except the custom field. We need the custom field in order to associate a payment with a certain service.
In our web app, we have the following:
paypalConfig = {
env: 'sandbox',
style: {
size: 'responsive',
color: 'white',
shape: 'rect',
label: 'pay',
layout: 'horizontal',
tagline: 'false'
},
client: {
sandbox: 'SANDBOX_ID',
},
commit: false,
payment: (data, actions) => {
console.log("data is", data, actions);
return actions.order.create({
payment: {
transactions: [
{ amount: { total: this.finalAmount * 100, currency: 'USD' }, job_id: this.jobId }
]
}
});
},
onApprove: (data, actions) => {
return actions.order.capture().then((details) => {
// This function shows a transaction success message to your buyer.
// alert('Transaction completed by ' + details.payer.name.given_name);
this.openModel('modal1');
}).catch(err => {console.log("Error in authorize in paypal", err); this.openModel('modal2');})
}
}
As you can see, the payment handler is adding a job_id property for the transaction object. In the back end, we are listening for the following events:
Checkout order completed, Payment capture completed, Payment sale completed
We only need to listen for an event (like Payment Received) that tells us when the transaction goes through. I wasn't sure so I added all events that seemed relevant because there wasn't any event named Payment Received.
Can this be done as we are trying here? We don't get the custom job_id field in the webhook.
First of all you appear to be using old PayPal checkout.js , switch to the newest sdk.js
Second of all you are using a client-side only integration, switch to a proper client-server pattern. Here is the front-end: https://developer.paypal.com/demo/checkout/#/pattern/server
You will need two corresponding routes on your server, 'Set Up Transaction' and 'Capture Transaction', documented here: https://developer.paypal.com/docs/checkout/reference/server-integration/
With the above solution, you have an immediate, synchronous API response on payment capture. There is no need for an additional asynchronous notification from webhooks, so those will essentially become superfluous to you.
Once all the above is working and creating successful transactions for you, there's one more thing to consider: propagating failures. That is, what happens in the case of an unhappy path, if the buyer's funding source fails to capture, e.g. their card is declined? There is a guide for how to send that error back to the UI, so they can add or choose a different card. Anyway, this is just the final detail to worry about.
Just create a paypal form and then add custom as one of the values. Heres an example. Also, here is a great tutorial to walk you through it https://youtu.be/HIwRzATH6iU
<form action="https://sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="amount" value="50.00">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="custom" value="{MemberID}">
<input type="hidden" name="business" value="youremail#business.example.com">
<input type="hidden" name="item_name" value="Whatever Item">
<input type="hidden" name="item_number" value="600">
<input type="hidden" name="no_shipping" value="2">
<input type="hidden" name="return" value="https://www.yourwebsite.com/success/">
<input type="hidden" name="cancel_return" value="https://www.yourwebsite.com/failure">
<input type="hidden" name="notify_url" value="https://www.yourwebsite.com/ipn">
<input type="submit" value="Pay Now" name="submit" title="PayPal - The safer, easier way to pay online!" class="btn btn-primary">
</form>

Which PAYPAL service is better for online transaction for website?

I am working on a website where users will have to pay to use some services. So I know that PayPal is the service I can use. User can pay with debit card, credit card, PayPal account etc. I know that PayPal button can be used for it. But in my website, I want to give user an option to add amount of their choice. User can pay $5 or $50,000 or anything they want. I don't know if I can use PayPal button or not for this.
In short user will enter amount in form. After submitting the form, it will redirect user to PayPal site where they can pay the amount. In return, I wanna make sure how much they have paid, and transaction was successful or not etc from PayPal so I can store details in database and if transaction was successful, user will get the amount balance in account.
So all I want to know is which service will be better for me from PayPal?
Like PayPal button or PayPal gateway or PayPal flow gateway?
I've done exactly this on my site. I'll post some code for it. Basically you create an input form that's not hidden, call it amount, so they user can enter the amount, then pass it to paypal. Paypal sites say it doesnt' work, but it does.
I used low end Paypal standard, not any of their fancier interfaces. I have the user add to cart then pay for the cart. But you can do the same for buy now buttons. It doesn't matter which paypal service you use. If it can be done with the basic paypal standard, you can do it with any of them...!
You can also get from paypal after the transaction, various aspects of what the user paid for. So there's a variable available for total amount, and individual amounts, and so on.
This is the key to setting up a donation amount for the user to input:
<input type="hidden" name="button_subtype" value="services">
and of course:
<b>Amount $: (Example: nnn.nn)</b>
<input type="text" name="amount">
I'm not as familar with the variables comign back from paypal. For what you want paypal standard should work from what I've read definitely. Here are the two ways to do it, and both work with paypal standard, so will work with any paypal:
This link Contains the two that follow below and also gives a brief overview.:
https://developer.paypal.com/webapps/developer/docs/classic/paypal-payments-standard/integration-guide/wp_standard_overview/
1)
https://developer.paypal.com/webapps/developer/docs/classic/paypal-payments-standard/integration-guide/paymentdatatransfer/
2)
https://developer.paypal.com/webapps/developer/docs/classic/ipn/integration-guide/IPNIntro/
Here's a body of code for the form.
<form target="_blank" action="https://www.paypal.com/cgi-bin/webscr" method="post">
value="https://www.yourwebsite.com/logo.jpg"> -->
<b>Amount $: (Example: nnn.nn)</b>
<input type="text" name="amount">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn /btn_cart_SM.gif" border="0" name="submit">
<input type="hidden" name="add" value="1">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="yours">
<input type="hidden" name="item_name" value="donation">
<input type="hidden" name="no_shipping" value="0">
<input type="hidden" name="shipping" value="0.00">
<input type="hidden" name="tax" value="0.00">
<!-- Replace value with the web page you want the customer to return to -->
<input type="hidden" name="shopping_url" value="http://www.yours">
<!-- services seems to be the trick -->
<input type="hidden" name="button_subtype" value="services">
<input type="hidden" name="country" value="US">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="bn" value="PP-ShopCartBF:btn_paynowCC_LG.gif:NonHosted">
</form>
I recommended use a paypal express checkout. Here one simple (PHP) example:
// Parameters for SetExpressCheckout, which will be sent to PayPal
$padata['L_BILLINGAGREEMENTDESCRIPTION0'] = 'Product description';
$padata['L_BILLINGAGREEMENTDESCRIPTION0'] = $padata['L_BILLINGAGREEMENTDESCRIPTION0'] .
' $'.$product->price.'/month';
$padata['L_PAYMENTREQUEST_0_DESC0'] = $padata['L_BILLINGAGREEMENTDESCRIPTION0'] .
' $'.$product->price.'/month';$padata['PAYMENTREQUEST_0_NOTIFYURL'] = 'http://site_url/paypal/ipn';
$padata['PAYMENTREQUEST_0_DESC'] = $product->name;
$padata['RETURNURL'] = 'http://site_url/paypal/returnurl';
$padata['CANCELURL'] = 'http://site_url/paypal/cancelurl';
$padata['PAYMENTREQUEST_0_CURRENCYCODE'] = 'USD';
$padata['PAYMENTREQUEST_0_PAYMENTACTION'] = 'SALE';
$padata['PAYMENTREQUEST_0_ITEMAMT'] = $product->price;$padata['PAYMENTREQUEST_0_AMT'] = $product->price;$padata['L_BILLINGTYPE0'] = 'RecurringPayments';$padata['L_PAYMENTREQUEST_0_NAME0'] = $product->name;$padata['L_PAYMENTREQUEST_0_NUMBER0']= '322';$padata['L_PAYMENTREQUEST_0_QTY0'] = '1';$padata['L_PAYMENTREQUEST_0_AMT0'] = $product->price;
$paypal_data = http_build_query($padata);
$httpParsedResponseAr = $this->PPHttpPost('SetExpressCheckout', $paypal_data);
//Respond according to message we receive from Paypal
if("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"])){
//Redirect user to PayPal store with Token received.
$paypalurl ='https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token='.$httpParsedResponseAr["TOKEN"].'';
header('Location: '.$paypalurl);
}else{
echo 'Error : '.urldecode($httpParsedResponseAr["L_LONGMESSAGE0"]).'';
}
Page returnurl:
$hosteddata['L_BILLINGAGREEMENTDESCRIPTION0'] = 'Recurring Description';$hosteddata['L_BILLINGAGREEMENTDESCRIPTION0'] = $hosteddata['L_BILLINGAGREEMENTDESCRIPTION0'] . ' $'.$pr->price.'/month';$hosteddata['L_PAYMENTREQUEST_0_NAME0'] = $pr->name;$hosteddata['PROFILEREFERENCE'] = $GetExpressCheckoutDetails['L_PAYMENTREQUEST_0_NUMBER0'];$hosteddata['PROFILESTARTDATE'] = date('Y-m-d') . 'T' . date('H:i:s').'Z';$hosteddata['SUBSCRIBERNAME'] = $GetExpressCheckoutDetails['FIRSTNAME'] . ' ' . $GetExpressCheckoutDetails['LASTNAME'];$hosteddata['TOKEN'] = urlencode($_POST['token']);$hosteddata['DESC'] = $hosteddata['L_BILLINGAGREEMENTDESCRIPTION0'];$hosteddata['AMT'] = $pr->price;$hosteddata['BILLINGPERIOD'] = 'Month';$hosteddata['BILLINGFREQUENCY'] = '1';$hosteddata['TOTALBILLINGCYCLES'] = '12';$hosteddata['REGULARTOTALBILLINGCYCLES'] = '1';$hosteddata['VERSION'] = '74.0';$hosteddata['MAXFAILEDPAYMENTS'] = '1';$hosteddata['L_PAYMENTREQUEST_0_QTY0'] = '1';$hosteddata['L_BILLINGTYPE0'] = 'RecurringPayments';$hosteddata['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Digital';$hosteddata['L_PAYMENTREQUEST_0_AMT0'] = $pr->price;$hosteddata['INITAMT'] = $pr->price;$hosteddata['L_PAYMENTREQUEST_0_NUMBER0'] = $pr->id;$hosteddata['PAYMENTREQUEST_0_NOTIFYURL'] = 'http://site_url/paypal/ipn';
$paypal_data = http_build_query($hosteddata);
$hosted_saas_response = $this->PPHttpPost('CreateRecurringPaymentsProfile', $paypal_data);
I used a separate method to post parameters to paypal
private function PPHttpPost( $methodName_, $nvpStr_ ) {
$api_username = 'yourpaypal#email.com';
$api_password = 'QWEQWEWQEQWEQEQWE';$api_signature = 'WQEQWEQWEQWEWQEQWEQWEQWEQWEQWE.cT';$api_endpoint = "https://api-3t.paypal.com/nvp";$version = '124.0';
$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $api_endpoint); curl_setopt($ch, CURLOPT_VERBOSE, 1);curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$nvpreq = "METHOD=$methodName_&VERSION=$version&PWD=$api_password&USER=$api_username&SIGNATURE=$api_signature&$nvpStr_";
curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);$httpResponse = curl_exec($ch);
if(!$httpResponse) {
exit("$methodName_ failed: ".curl_error($ch).'('.curl_errno($ch).')');}
// Extract the response details.
$httpResponseAr = explode("&", $httpResponse);
$httpParsedResponseAr = array();
foreach ($httpResponseAr as $i => $value) {
$tmpAr = explode("=", $value);
if(sizeof($tmpAr) > 1) {
$httpParsedResponseAr[$tmpAr[0]] = $tmpAr[1];
}
}
if((0 == sizeof($httpParsedResponseAr)) || !array_key_exists('ACK', $httpParsedResponseAr)) {
exit("Invalid HTTP Response for POST request($nvpreq) to $api_endpoint.");
}
return $httpParsedResponseAr;
}

Status Detail: 5068 when using sagePay

I am trying to use SagePay. I have an account and I would like to use Server Integration.
The error I get is Status Detail: 5068 : The encryption method is not supported by this protocol version.
I'm trying to create a simple 'pay now' button, as described in the documents. The code samples provided by sage don't appear to work.
Can someone please let me know why the code below doesnt work? thanks
<?php
require_once ('lib/SagePay.php');
$sagePay = new SagePay();
$sagePay->setCurrency('BG');
$sagePay->setAmount('100');
$sagePay->setDescription('Lorem ipsum');
$sagePay->setBillingSurname('Mustermann');
$sagePay->setBillingFirstnames('Max');
$sagePay->setBillingCity('Cologne');
$sagePay->setBillingPostCode('50650');
$sagePay->setBillingAddress1('Bahnhofstr. 1');
$sagePay->setBillingCountry('de');
$sagePay->setDeliverySameAsBilling();
/* Example of using BasketXML */
$xml = new DOMDocument();
$basketNode = $xml->createElement("basket");
$itemNode = $xml->createElement("item");
$descriptionNode = $xml->createElement( 'description' );
$descriptionNode->nodeValue = 'First Item Description';
$itemNode -> appendChild($descriptionNode);
$quantityNode = $xml->createElement('quantity');
$quantityNode->nodeValue = '1';
$itemNode -> appendChild($quantityNode);
$unitNetAmountNode = $xml->createElement('unitNetAmount');
$unitNetAmountNode->nodeValue = '90.00';
$itemNode -> appendChild($unitNetAmountNode);
$unitTaxAmountNode = $xml->createElement('unitTaxAmount');
$unitTaxAmountNode->nodeValue = '10.00';
$itemNode -> appendChild($unitTaxAmountNode);
$unitGrossAmountNode = $xml->createElement('unitGrossAmount');
$unitGrossAmountNode->nodeValue = '100.00';
$itemNode -> appendChild($unitGrossAmountNode);
$totalGrossAmountNode = $xml->createElement('totalGrossAmount');
$totalGrossAmountNode->nodeValue = '100.00';
$itemNode -> appendChild($totalGrossAmountNode);
$basketNode->appendChild( $itemNode );
$xml->appendChild( $basketNode );
$sagePay->setBasketXML($xml->saveHTML());
$sagePay->setSuccessURL('https://website.co.uk/page.html');
$sagePay->setFailureURL('https://website.co.uk/page.html');
?>
<form method="POST" id="SagePayForm" action="https://test.sagepay.com/gateway/service/vspform-register.vsp">
<input type="hidden" name="VPSProtocol" value= "3.00">
<input type="hidden" name="TxType" value= "PAYMENT">
<input type="hidden" name="Vendor" value= "vendorname here">
<input type="hidden" name="Crypt" value= "<?php echo $sagePay->getCrypt(); ?>">
<input type="submit" value="continue to SagePay">
</form>
Couple of things to check:
Ensure you are using AES encryption on the Crypt field
When sending the crypt over to Sage Pay, make sure it is prefixed '#'
Make sure you are not Base64 encoding the string after you have AES encrypted it (the protocol documents are a little misleading in this regard)
[update]: 4. You are actually using the Form integration method...
Thanks for the help on this.
It was a problem with the encryption method. The code that eventually worked for me was this one:
https://github.com/tolzhabayev/sagepayForm-php/blob/master/lib/SagePay.php
And my form button is like this:
<form method="POST" id="SagePayForm" action="https://test.sagepay.com/gateway/service/vspform-register.vsp">
<input type="hidden" name="VPSProtocol" value= "3.00">
<input type="hidden" name="TxType" value= "PAYMENT">
<input type="hidden" name="Vendor" value= "vendornamehere">
<input type="hidden" name="Crypt" value= "<?php echo $sagePay->getCrypt(); ?>">
<input type="submit" value="continue to SagePay">
</form>

How to capture authorized PayPal payment automatically in paypal standard?

I want to implement paypal authorization and capture payment automatically. I have used paypal standard account. I have send payment request with authorization parameter.
<form:form commandName="paymentForm" id="paymentForm" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" name="paypal">
<form:input path="cmd" id="cmd" name="cmd" type="hidden" />
<form:input path="business" id="business" name="business" type="hidden" />
<form:input path="password" id="password" name="password" type="hidden" />
<form:input path="custom" id="custom" name="custom" type="hidden" />
<form:input path="item_name" id="item_name" name="item_name" type="hidden" />
<form:input path="amount" id="amount" name="amount" type="hidden" />
<form:input path="currencyCode" type="hidden" name="currency_code" value="EUR" />
<form:input path="rm" id="rm" name="rm" type="hidden" />
<%-- <form:input path="returnUrl" id="return" name="return" type="hidden" /> --%>
<form:input type="hidden" name="return" value="${paymentForm.returnUrl}" />
<form:input type="hidden" name="cancel_return" path="cancel_return" />
<form:input type="hidden" name="cert_id" path="certId" />
<form:input type="hidden" name="paymentaction" path="authorization">
</form:form>
Now I want to capture the payment by using sending Http request to paypal with transaction Id/ authorization Id. How can I do this?
Thanks In Advance
K.Lakshmi Priya
You would need to make an API call to the DoCapture API call.
If you haven't used PayPal's API calls before, I suggest reading the Getting Started guide as well.
The following java code make Capture the authorized payment by using DoCapture API Call
import com.paypal.sdk.core.nvp.NVPDecoder;
import com.paypal.sdk.core.nvp.NVPEncoder;
import com.paypal.sdk.exceptions.PayPalException;
import com.paypal.sdk.profiles.APIProfile;
import com.paypal.sdk.profiles.ProfileFactory;
import com.paypal.sdk.services.NVPCallerServices;
public class DoCapture {
public static final String DO_CAPTURE_METHOD = "DoCapture";
public static void main(String[] args) throws PayPalException {
APIProfile profile;
profile = ProfileFactory.createSignatureAPIProfile();
profile.setAPIUsername("API User Name");
profile.setAPIPassword("PWD");
profile.setSignature("API Signature");
// profile.setEnvironment("sandbox");
// profile.setSubject("");
// profile.setTimeout(timeout);
NVPEncoder encoder = new NVPEncoder();
NVPDecoder decoder = new NVPDecoder();
NVPCallerServices caller = new NVPCallerServices();
caller.setAPIProfile(profile);
encoder.add("METHOD", DO_CAPTURE_METHOD);
encoder.add("AUTHORIZATIONID", "8PR03910DP1572333");
encoder.add("COMPLETETYPE", "Complete");
encoder.add("AMT", "100");
encoder.add("CURRENCYCODE", "EUR");
String NVPRequest = encoder.encode();
String NVPResponse = caller.call(NVPRequest);
decoder.decode(NVPResponse);
System.out.println("PayPal Response :: "+NVPResponse);
}
}
For more detail refer https://developer.paypal.com/webapps/developer/docs/classic/api/merchant/DoCapture_API_Operation_NVP/
In c# you can capture payment using following code.
public ActionResult CaptureAuthorization()
{
APIContext apiContext = Configuration.GetAPIContext();
try
{
Authorization authorization = Authorization.Get(apiContext, "6SY29185GS4409204");//Provide Payment Id returned after authorizing payment.
Capture capture = new Capture();
Amount captureAmount = new Amount();
captureAmount.currency = "USD";
captureAmount.total = "7";
capture.amount = captureAmount;
Capture responseCap = authorization.Capture(apiContext, capture);//Capture Payment
if (responseCap.state.ToLower() != "completed")
{
return View("Failure");
}
return View("Success");
}
catch (Exception ex)
{
return View("Failure");
}
}

Paypal Sandbox payment problem

I have the following post button that i use for paypal transactions:
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="my#email.com">
<input type="hidden" name="item_name" value="Item description">
<input type="hidden" name="item_number" value="1">
<input type="hidden" name="amount" value="00.30">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="bn" value="PP-BuyNowBF">
<input type="hidden" name="return" value="website.com/index.php" />
<input type="hidden" name="cancel_return" value="website.com/index.php" />
<input type="hidden" name="rm" value="2">
<input type="hidden" name="notify_url" value="website.com/ipn/ipn.php">
<input type="hidden" name="custom" value="user_id">
<input type="submit" value="upgrade" />
</form>
and the following code in ipn.php
<?php
include_once 'config.php';
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
//$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
// assign posted variables to local variables
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
// check the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment
mysql_query("UPDATE table SET column='1' WHERE column2='13'");
}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}
}
fclose ($fp);
}
?>
when i click the upgrade button and pay, it doesnt show me a go back to the website button... but there is a go back to my#email.com button, which has a 10 sec delay and takes me back to my website... although it popups a warning about encrypted data, which i dont know what it is.
Also the query i use in ipn.php does not execute.I dont even know if it goes to ipn.php.
Regarding go back to "my#email.com", this could happen if the email you specified doesn't map to an account in the PayPal sandbox. Perhaps you're using your real email in the button instead of a sandbox account email?
Another possibility is that your test account at "my#email.com" is not a business account. If you have a business account it should reflect your business name instead.
As for not receiving the IPNs, the sandbox doesn't always do a great job at delivering IPNs on time, if at all. I'd actually suggest that you try integrating using Express Checkout instead of Website Payments Standard. Express Checkout is a little bit of a confusing dance initially but it is easy to implement after you try to understand it. Here's what I think is the best doc explaining how Express Checkout works:
https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_ECSimpleIntegration
And when you're ready to dive into the implementation you should look here:
https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/howto_api_reference
The nice thing about using Express Checkout instead of relying on IPN is that you get to figure out the payment status the moment your user returns to your site, and you don't have to sit around waiting for the IPN to show up.
With Express Checkout you also get to override your business name with a custom "brand name" so you can use the same receiving PayPal account on different sites with different "brands".
Good luck!