Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to create Encrypted PayNow button "on the fly" for Third-party customers, using Paypal NVP API?
    primarykey
    data
    text
    <p>I need to create Encrypted "PayNow" paypal buttons on the fly for a website.<br> I read all the documentation I can find on the paypal website.<br> I understood that I need to use the BMCreateButton ButtonManager NVP API.<br> But I've been unable to find any information, nor any reasonably simple and documented sample code, about HOW I'm supposed to call these API. </p> <p>Do I need to put my parameter in a form and post it on some kind of server?<br> Do I need to put all the parameter on an url, call this url, ad use the result?<br> How do I authenticate to this service?<br> I'm going to create encrypted paynow button for different paypal business account.</p> <p>Can someone show me some VB.Net or C# code that actually call this BMCreateButton NVP API?<br> So that I can see:</p> <ul> <li>how to do the call</li> <li>how to authenticate to the service</li> <li>how to format/use the parameters of the API call</li> <li>how to get the results</li> </ul> <p><strong><em>Various link to useful resource</em></strong><br> - Thanks to <a href="https://stackoverflow.com/a/5225809/1057961">this answer</a> I've been able to find some useful sample code <a href="http://brad.w3portals.com/2008/02/paypal-nvp-api-example-in-c-aspnet.html" rel="nofollow noreferrer">here</a> and <a href="http://brad.w3portals.com/2008/03/paypal-nvp-api-example-for-vbnet-aspnet.html" rel="nofollow noreferrer">there</a> about how to call Paypal API.<br> - <a href="https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&amp;content_ID=developer/e_howto_api_nvp_NVPAPIOverview" rel="nofollow noreferrer">Here</a> is more usefull information about how paypal NVP API works.<br> - <a href="http://quar.me/paypal/api/nvp/bmcreatebutton" rel="nofollow noreferrer">Here</a> an interesting website that generate API Call URL for the BMCreateButton API<br> - <a href="https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&amp;content_ID=developer/e_howto_api_ECAPICredentials" rel="nofollow noreferrer">Here</a> you can find instruction for obtaining "Third Party" API credentials. (thanks to <a href="https://stackoverflow.com/a/7431815/1057961">this answer</a>)<br> - Some more useful information <a href="http://coding.smashingmagazine.com/2011/09/05/getting-started-with-the-paypal-api/" rel="nofollow noreferrer">here</a> about Paypal API integration<br> - <a href="https://developer.paypal.com/docs/classic/release-notes/#ec" rel="nofollow noreferrer">Here</a> you can find the current and latest version number of the Paypal API </p> <p><strong><em>Update 1</em></strong><br> Now I've created some code that actually do something, but it give me an error. This code actually create an encrypted paynow button using the BMCreateButton API. It seem to works, but when I click the paynow button, it show all the payment parameters, but also show the error <strong><em>"There was a problem with the decryption of your secure order. Please contact your merchant."</em></strong></p> <p><strong>Here is the code</strong>: </p> <pre><code>Public Shared Sub PaypalTest3web() Dim NVP As New Dictionary(Of String, String) Dim strUsername As String = "aso_1273063882_biz_api3.megatesto.it" Dim strPassword As String = "1273063582" Dim strSignature As String = "A22sd7623RGUsduDHDSFU57N7dfhfS23DUYVhdf85du8S6FJ6D5bfoh5" Dim strNVPSandboxServer As String = "https://api-3t.sandbox.paypal.com/nvp" NVP.Add("USER", strUsername) NVP.Add("PWD", strPassword) NVP.Add("SIGNATURE", strSignature) Dim bvCount As Integer bvCount = 0 NVP.Add("METHOD", "BMCreateButton") NVP.Add("VERSION", "85.0") NVP.Add("BUTTONCODE", "ENCRYPTED") ''CLEARTEXT / ENCRYPTED NVP.Add("BUTTONTYPE", "BUYNOW") NVP.Add("BUTTONSUBTYPE", "PRODUCTS") ''Optional: PRODUCTS / SERVICES bvCount = bvCount + 1 : NVP.Add("L_BUTTONVAR" &amp; bvCount, "business=D64TG758HIWj2") ''Merchant ID 'bvCount = bvCount + 1 : NVP.Add("L_BUTTONVAR" &amp; bvCount, "cmd=_s-xclick") ''DONT SPECIFY the cmd parameter, if specifien it will generate an error on the decription of the "secure order", I don't know why... 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") ''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(strNVPSandboxServer), HttpWebRequest) wrWebRequest.Method = "POST" Dim requestWriter As New StreamWriter(wrWebRequest.GetRequestStream()) requestWriter.Write(param) requestWriter.Close() '' Get the response. Dim responseReader As StreamReader responseReader = New StreamReader(wrWebRequest.GetResponse().GetResponseStream()) ''and 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; strNVPSandboxServer &amp; vbCrLf &amp; HttpUtility.UrlDecode(param.Replace("&amp;", vbCrLf &amp; " ")) &amp; vbCrLf &amp; vbCrLf &amp; "Result:" &amp; vbCrLf &amp; result &amp; vbCrLf &amp; vbCrLf &amp; "--------------------------------------" &amp; vbCrLf ''show the results Trace.WriteLine(result) MessageBox.Show(result) End Sub </code></pre> <p><strong>Here is the HTML Response</strong></p> <pre><code>&lt;form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post"&gt; &lt;input type="hidden" name="cmd" value="_s-xclick"&gt; &lt;input type="hidden" name="encrypted" value="-----BEGIN PKCS7-----MIIHwgYJKoZIhvcNAQcEoIIHszCCB68CAQExggE6MIIBNgIBADCBnjCBmDELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWEx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YW5kYm94X2NlcnRzMRQwEgYDVQQDFAtzYW5kYm94X2FwaTEcMBoGCSqGSIb3DQEJARYNcmVAcGF5cGFsLmNvbQIBADAJBgUrDgMCGgUAoF0wGAYJKoZIhvcNAQkDMQsGCSqGSIb3DQEHATAcBgkqhkiG9w0BCQUxDxcNMTIwNDAzMDcxMDA5WjAjBgkqhkiG9w0BCQQxFgQUl2SP4H6+jn0c8fejmdZ5IoeJcPMwDQYJKoZIhvcNAQEBBQAEgYCjmQurKhtDO2g9/qbrvaxXHVRMP54jncODgLAMbauYHALYJlk2r5k+Q3x/GAuuiaj47A0qGlPoyQ/WddHYF0R4Ffph0ocrAXLH9RC8jz2Cqx+rt/8FIa7h1OhDwIhJynJ6eIPMfzm3T0wytZa6x8GnZaOJ0MtKqOeojkZjL61feQ==-----END PKCS7----- "&gt; &lt;input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_buynow_LG.gif" border="0" name="submit" alt="PayPal - Il sistema di pagamento online più facile e sicuro!"&gt; &lt;img alt="" border="0" src="https://www.sandbox.paypal.com/it_IT/i/scr/pixel.gif" width="1" height="1"&gt; &lt;/form&gt; </code></pre> <p><strong>And here is the error I get after clicking on this encrypted pay-now button</strong></p> <p><img src="https://i.stack.imgur.com/FOpS5.png" alt="enter image description here"></p> <p>As you can see, all the parameters (item name, price, item_id...) are correct. But I'm unable to understand why I'm getting this error. </p> <p>If you want to try this code you should substitute your API user/password/signature. The generated PayNow button only works when you are logged in your paypal sandbox account.</p> <p>Do you have any idea about how to solve this error?</p> <p><strong>Note:</strong> after solving this issue, I'll need to understand how to create encrypted button for a third paypal business account (we will need to create encrypted button for paypal accounts of our customers). Using our API credentials, customer merchant code, and having our API credential configured up in our customers paypal account isn't enought... It say that merchant code is not valid. Probably I'm missing something...</p> <p><strong><em>Update 2</em></strong><br> It seem that I've found how to solve the aforementioned error: simply remove the "cmd=_s-xclick / _xclick" parameters. If the "cmd" is not specified, the paynow button doesn't seem to generate any error. More testing is needed... anyway I've commented the code line in the code example.</p> <p>Now, back to business. Let's do some testing, and then find the proper way to create paynow button for third party paypal accounts.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    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