Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ok, finally I got it! :-)</p> <p><strong>My objective is to create <em>Encrypted</em> PayNow buttons "on the fly" for some of our customers.</strong> Here is a brief explanation of how PayPal API works with Third-party access. </p> <ul> <li>Create a Paypal Sandbox account (<a href="https://developer.paypal.com/" rel="nofollow noreferrer">here</a>)</li> <li>In this sandbox account, create 2 new business account<br> <em>you should hook these business account to a credit card. This will mark these account as "verified", unless it won't work</em> <ul> <li>The first account (account A) will represent our company</li> <li>The second account (account B) will represent one of our customers</li> </ul></li> <li>log in account A, and request the API credentials (<a href="https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&amp;content_ID=developer/e_howto_api_ECAPICredentials" rel="nofollow noreferrer">instructions here</a>)</li> <li>log in account B, and grant API permission to account A (<a href="https://www.paypalobjects.com/IntegrationCenter/ic_shoppingcartresources.html" rel="nofollow noreferrer">instruction here</a> check the paragraph "<em>Third-party authentication: Grant your cart the appropriate API authentication permissions</em>")</li> <li>grab the Api credentials of account A, and put them in your source code</li> <li>grab Merchant ID and merchant Email of account B and put them in your source code</li> <li>run the code</li> <li>grab the returned html, put it on a web page, and test it, it should works<br> <em>(you need to be logged on your paypal sandbox account, or the generated button wont works)</em></li> </ul> <p><em>Why this simple and concise knowledge is timewastingly scattered among a countless number of PayPal help pages, PayPal PDF manuals, and third party blog post, is beyond my understanding :-) Anyway...</em></p> <p><strong><em>Here is the working code in VB.Net</em></strong></p> <pre><code>Public Shared Sub PaypalThirdPartyPayNowButtonTest() Dim bvCount As Integer = 0 ''L_BUTTONVAR counter Dim NVP As New Dictionary(Of String, String) ''Api Name-Value-Pair parameters ''define paypal SANDBOX server Dim paypalApiServerUrl As String = "https://api-3t.sandbox.paypal.com/nvp" ''define Api credentials of YOUR business paypal account Dim yourApiUsername As String = "aso_1273063882_biz_api3.megatesto.it" Dim yourApiPassword As String = "1273063582" Dim yourApiSignature As String = "A22sd7623RGUsduDHDSFU57N7dfhfS23DUYVhdf85du8S6FJ6D5bfoh5" ''define Your CUSTOMER identification data Dim customerEmailID As String = "MyCustomer_143363961_biz@megatesto.it" Dim customerMerchantID As String = "3S4EF7BI96YHS" ''use YOUR identification data NVP.Add("USER", yourApiUsername) NVP.Add("PWD", yourApiPassword) NVP.Add("SIGNATURE", yourApiSignature) ''use your CUSTOMER identification data NVP.Add("SUBJECT", customerEmailID) bvCount = bvCount + 1 : NVP.Add("L_BUTTONVAR" &amp; bvCount, "business=" &amp; customerMerchantID) ''Merchant ID ''Api method name and version NVP.Add("METHOD", "BMCreateButton") NVP.Add("VERSION", "85.0") ''method specific parameters NVP.Add("BUTTONCODE", "ENCRYPTED") NVP.Add("BUTTONTYPE", "BUYNOW") NVP.Add("BUTTONSUBTYPE", "PRODUCTS") ''Buynow button specific parameters bvCount = bvCount + 1 : NVP.Add("L_BUTTONVAR" &amp; bvCount, "lc=IT") bvCount = bvCount + 1 : NVP.Add("L_BUTTONVAR" &amp; bvCount, "button_subtype=PRODUCTS") bvCount = bvCount + 1 : NVP.Add("L_BUTTONVAR" &amp; bvCount, "item_name=Test_product") bvCount = bvCount + 1 : NVP.Add("L_BUTTONVAR" &amp; bvCount, "item_number=123456") bvCount = bvCount + 1 : NVP.Add("L_BUTTONVAR" &amp; bvCount, "amount=12.00") bvCount = bvCount + 1 : NVP.Add("L_BUTTONVAR" &amp; bvCount, "currency_code=EUR") bvCount = bvCount + 1 : NVP.Add("L_BUTTONVAR" &amp; bvCount, "quantity=1") ''bvCount = bvCount + 1 : NVP.Add("L_BUTTONVAR" &amp; bvCount, "cmd=_s-xclick") 'DONT' specify the cmd parameter, if you specify it, it wont work, paypal will give you an error ''build the parameter string Dim paramBuilder As New StringBuilder For Each kv As KeyValuePair(Of String, String) In NVP Dim st As String st = kv.Key &amp; "=" &amp; HttpUtility.UrlEncode(kv.Value) &amp; "&amp;" paramBuilder.Append(st) Next Dim param As String param = paramBuilder.ToString param = param.Substring(0, param.Length - 1) ''remove the last '&amp;' ''Create web request and web response objects, make sure you using the correct server (sandbox/live) Dim wrWebRequest As HttpWebRequest = DirectCast(WebRequest.Create(paypalApiServerUrl), HttpWebRequest) wrWebRequest.Method = "POST" Dim requestWriter As New StreamWriter(wrWebRequest.GetRequestStream()) requestWriter.Write(param) requestWriter.Close() '' Get the responseReader Dim responseReader As StreamReader responseReader = New StreamReader(wrWebRequest.GetResponse().GetResponseStream()) ''read the response Dim responseData As String responseData = responseReader.ReadToEnd() responseReader.Close() ''url-decode the results Dim result As String result = HttpUtility.UrlDecode(responseData) Dim formattedResult As String formattedResult = "Request on " &amp; paypalApiServerUrl &amp; vbCrLf &amp; HttpUtility.UrlDecode(param.Replace("&amp;", vbCrLf &amp; " ")) &amp; vbCrLf &amp; vbCrLf &amp; "Result:" &amp; vbCrLf &amp; HttpUtility.UrlDecode(responseData.Replace("&amp;", vbCrLf &amp; " ")) &amp; vbCrLf &amp; vbCrLf &amp; "--------------------------------------" &amp; vbCrLf ''show the results Trace.WriteLine(formattedResult) MessageBox.Show(formattedResult) End Sub </code></pre> <p><strong><em>And here is the same code in C#</em></strong></p> <pre><code>public static void PaypalThirdPartyPayNowButtonTest() { int bvCount = 0; //L_BUTTONVAR counter Dictionary&lt;string, string&gt; NVP = new Dictionary&lt;string, string&gt;(); //Api Name-Value-Pair parameters //paypal SANDBOX server string paypalApiServerUrl = "https://api-3t.sandbox.paypal.com/nvp"; //Api credentials of YOUR business paypal account string yourApiUsername = "aso_1273063882_biz_api3.megatesto.it"; string yourApiPassword = "1273063582"; string yourApiSignature = "A22sd7623RGUsduDHDSFU57N7dfhfS23DUYVhdf85du8S6FJ6D5bfoh5"; //Your CUSTOMER identification data string customerEmailID = "MyCustomer_143363961_biz@megatesto.it"; string customerMerchantID = "3S4EF7BI96YHS"; //use YOUR identification data NVP.Add("USER", yourApiUsername); NVP.Add("PWD", yourApiPassword); NVP.Add("SIGNATURE", yourApiSignature); //use your CUSTOMER identification data NVP.Add("SUBJECT", customerEmailID); bvCount++; NVP.Add("L_BUTTONVAR" + bvCount.ToString() , "business=" + customerMerchantID); //Api method name and version NVP.Add("METHOD", "BMCreateButton"); NVP.Add("VERSION", "85.0"); //method specific parameters NVP.Add("BUTTONCODE", "ENCRYPTED"); NVP.Add("BUTTONTYPE", "BUYNOW"); NVP.Add("BUTTONSUBTYPE", "PRODUCTS"); //Buynow button specific parameters bvCount++; NVP.Add("L_BUTTONVAR" + bvCount.ToString() , "lc=IT"); bvCount++; NVP.Add("L_BUTTONVAR" + bvCount.ToString() , "button_subtype=PRODUCTS"); bvCount++; NVP.Add("L_BUTTONVAR" + bvCount.ToString() , "item_name=Test_product"); bvCount++; NVP.Add("L_BUTTONVAR" + bvCount.ToString() , "item_number=123456"); bvCount++; NVP.Add("L_BUTTONVAR" + bvCount.ToString() , "amount=12.00"); bvCount++; NVP.Add("L_BUTTONVAR" + bvCount.ToString() , "currency_code=EUR"); bvCount++; NVP.Add("L_BUTTONVAR" + bvCount.ToString() , "quantity=1"); //bvCount = bvCount + 1 : NVP.Add("L_BUTTONVAR" &amp; bvCount, "cmd=_s-xclick") //DON'T specify the cmd parameter, if you specify it, it wont work, paypal will give you an error //build the parameter string StringBuilder paramBuilder = new StringBuilder(); foreach (KeyValuePair&lt;string, string&gt; kv in NVP) { string st = kv.Key + "=" + System.Web.HttpUtility.UrlEncode(kv.Value) + "&amp;"; paramBuilder.Append(st); } string param = paramBuilder.ToString(); param = param.Substring(0, param.Length - 1); //remove the last '&amp;' //Create web request and web response objects, make sure you using the correct server (sandbox/live) System.Net.HttpWebRequest wrWebRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(paypalApiServerUrl); wrWebRequest.Method = "POST"; System.IO.StreamWriter requestWriter = new System.IO.StreamWriter(wrWebRequest.GetRequestStream()); requestWriter.Write(param); requestWriter.Close(); //Get the responseReader System.IO.StreamReader responseReader = new System.IO.StreamReader(wrWebRequest.GetResponse().GetResponseStream()); string responseData = responseReader.ReadToEnd(); responseReader.Close(); //url-decode the results string result = System.Web.HttpUtility.UrlDecode(responseData); string formattedResult = "Request on " + paypalApiServerUrl + "\r\n" + System.Web.HttpUtility.UrlDecode(param.Replace("&amp;", "\r\n ")) + "\r\n\r\nResult:\r\n" + System.Web.HttpUtility.UrlDecode(responseData.Replace("&amp;", "\r\n ")) + "\r\n\r\n--------------------------------------\r\n"; //show the results System.Diagnostics.Trace.WriteLine(formattedResult); System.Windows.Forms.MessageBox.Show(formattedResult); } </code></pre> <p><strong><em>I wish everyone a happy PayPal integration :-)</em></strong></p> <p><strong><em>Update (for PHP coder)</em></strong><br> @Style is asking for a working PHP example... I don't know PHP, but I've found some links that may contain useful information for PHP coder,: you can look for BMCreateButton api inside these source files: </p> <ul> <li><a href="https://stackoverflow.com/questions/14696322/paypal-authorization-failed">PayPal &quot;Authorization Failed&quot;</a> </li> <li><a href="https://stackoverflow.com/questions/7343757/working-example-of-paypal-website-payments-pro-hosted-solution-iframe">Working example of paypal Website Payments Pro Hosted Solution Iframe?</a> </li> <li><a href="http://code.google.com/p/my-project-phi/source/browse/trunk/Application/Services/PayPalService.php?r=61" rel="nofollow noreferrer">http://code.google.com/p/my-project-phi/source/browse/trunk/Application/Services/PayPalService.php?r=61</a> </li> <li><a href="http://plugins.svn.wordpress.org/stageshow/tags/1.1.4/include/mjslib_paypal_api.php" rel="nofollow noreferrer">http://plugins.svn.wordpress.org/stageshow/tags/1.1.4/include/mjslib_paypal_api.php</a> </li> <li><a href="http://plugins.svn.wordpress.org/stageshow/trunk/include/mjslib_paypal_api.php" rel="nofollow noreferrer">http://plugins.svn.wordpress.org/stageshow/trunk/include/mjslib_paypal_api.php</a> </li> <li><a href="http://my-project-phi.googlecode.com/svn-history/r61/trunk/Application/Services/PayPalService.php" rel="nofollow noreferrer">http://my-project-phi.googlecode.com/svn-history/r61/trunk/Application/Services/PayPalService.php</a> </li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload