Solved

Paypal Express -

Posted on 2013-01-23
15
1,042 Views
Last Modified: 2016-03-24
Hi Experts,

I'm trying to implement Paypal express my website.

I have successfully integrated it and test it with the Paypal sandbox, no problems.

So I am now trying to put it liven real, not in the sandbox.
But I've got the following error message:
HTTP Status 405 - Request method 'POST' not supported

I have read on the web it may be caused by the cookies, I deleted them but the bug persists.

Any idea what it wrong ?

Thanks

Here are the code I use:
<cfif Session.ccard NEQ "Paypal">
	<form action="order_confirmed.cfm" method="post">
		<td><input type="submit" name="confirm" value="Confirm my order" onClick="processing();" /></td>
	</form>
<cfelse>
	<cfform name="ppExpForm" method="post" action="#CGI.SCRIPT_NAME#?ppExp=true">
		<td> <input type="image" name="submit" src="https://www.paypalobjects.com/en_GB/GB/i/btn/btn_xpressCheckout.gif" id="submit" runat="server" onclick="processing();"></td>
	</cfform>
</cfif>

Open in new window


<!--- SetExpressCheckout --->
<cfif CGI.request_method eq "POST" AND isdefined("URL.ppExp") AND URL.ppExp eq "true">
	<!--- set our values to send to paypal into a struct --->
	<cfset VARIABLES.ppVals = structnew()>
	
	<cfset VARIABLES.ppVals.method = "SetExpressCheckout">
	<cfset VARIABLES.ppVals.paymentAction = "Sale">
	<cfset VARIABLES.ppVals.user = "x">
	<cfset VARIABLES.ppVals.pwd = "x">
	<cfset VARIABLES.ppVals.signature = "x">
	<cfset VARIABLES.ppVals.version = "52">
	<cfset VARIABLES.ppVals.amt = NumberFormat(session.totalBasketPrice + session.shipping, '___.__')>
	<cfset VARIABLES.ppVals.returnurl = "https://www.joe-cool.co.uk/EN/basket2/checkout.cfm">
	<cfset VARIABLES.ppVals.cancelurl = "https://www.joe-cool.co.uk/EN/basket/shopping_basket.cfm">
	
	<!--- call the method to initiate the pp request ---> <!--- test url = https://api-3t.sandbox.paypal.com/nvp --->
	<cfinvoke component="CallerService" method="doHttppost" requestdata="#VARIABLES.ppVals#" serverurl="https://www.paypal.com/uk/cgi-bin/webscr" returnvariable="VARIABLES.response">
	
	<!--- send data to method to return it as a struct --->
	<cfinvoke component="CallerService" method="getNVPResponse" nvpString="#URLDecode(VARIABLES.response)#" returnvariable="VARIABLES.responseStruct">
	
	<!--- check if the connection with paypal was a success --->
	<cfif isdefined("VARIABLES.responseStruct.ack") AND VARIABLES.responseStruct.ack eq "success">
		<!--- send the user to paypal login --->
		<cflocation url="https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=#VARIABLES.responseStruct.token#"  addtoken="false">
	<cfelse>
		<!--- output an error message --->
		<p style="text-align:center;color:red;font-size:x-large;">Sorry. There was a problem connecting with the PayPal server.</p>
		<p style="text-align:center;"><cfdump var="#VARIABLES.responseStruct#"></p>
	</cfif>
</cfif>

<!--- GetExpressCheckoutDetails --->
<cfif isdefined("URL.token") AND isdefined("URL.payerid")>
	<!--- set our values to send to paypal into a struct --->
	<cfset VARIABLES.ppVals = structnew()>
	
	<cfset VARIABLES.ppVals.method = "GetExpressCheckoutDetails">
	<cfset VARIABLES.ppVals.user = "x">
	<cfset VARIABLES.ppVals.pwd = "x">
	<cfset VARIABLES.ppVals.signature = "x">
	<cfset VARIABLES.ppVals.version = "52">
	<cfset VARIABLES.ppVals.token = URL.token>
	
	<!--- call the method to initiate the pp request --->
	<cfinvoke component="CallerService" method="doHttppost" requestdata="#VARIABLES.ppVals#" serverurl="https://www.paypal.com/uk/cgi-bin/webscr" returnvariable="VARIABLES.response">
	
	<!--- send data to method to return it as a struct --->
	<cfinvoke component="CallerService" method="getNVPResponse" nvpString="#URLDecode(VARIABLES.response)#" returnvariable="VARIABLES.responseStruct">
	
	<!--- if we get back the details set them into the user session --->
	<cfif isdefined("VARIABLES.responseStruct.ack") AND VARIABLES.responseStruct.ack eq "success">
		<cfset SESSION.user.countryCode = VARIABLES.responseStruct.countrycode>
		<cfset SESSION.user.email = VARIABLES.responseStruct.email>
		<cfset SESSION.user.firstName = VARIABLES.responseStruct.firstname>
		<cfset SESSION.user.lastName = VARIABLES.responseStruct.lastname>
		<cfset SESSION.user.payerid = VARIABLES.responseStruct.payerid>
		<cfset SESSION.user.payerstatus = VARIABLES.responseStruct.payerstatus>
		<cfset SESSION.user.shippingCountryCode = VARIABLES.responseStruct.shiptocountrycode>
		<cfset SESSION.user.shippingCountryName = VARIABLES.responseStruct.shiptocountryname>
		<cfset SESSION.user.shippingName = VARIABLES.responseStruct.shiptoname>
		<cfset SESSION.user.shippingCity = VARIABLES.responseStruct.shiptocity>
		<cfset SESSION.user.shippingState = VARIABLES.responseStruct.shiptostate>
		<cfset SESSION.user.shippingAddress = VARIABLES.responseStruct.shiptostreet>
		<cfset SESSION.user.shippingZipCode = VARIABLES.responseStruct.shiptozip>
		<cfset SESSION.user.token = VARIABLES.responseStruct.token>
		
		<!--- move the user to the billing and shipping page --->
		<cflocation url="https://www.joe-cool.co.uk/EN/basket2/checkout.cfm?ppDo=true" addtoken="false">
	<cfelse>
		<!--- output an error message --->
		<p style="text-align:center;color:red;font-size:x-large;">Sorry. There was a problem connecting with the PayPal server.</p>
		<p style="text-align:center;"><!---<cfdump var="#VARIABLES.responseStruct#">---></p>
	</cfif>
</cfif>

<!--- DoExpressCheckoutPayment --->
<cfif isdefined("URL.ppDo") AND URL.ppDo eq "true">
	<!--- set our values to send to paypal into a struct --->
	<cfset VARIABLES.ppVals = structnew()>
	
	<cfset VARIABLES.ppVals.method = "DoExpressCheckoutPayment">
	<cfset VARIABLES.ppVals.user = "x">
	<cfset VARIABLES.ppVals.pwd = "x">
	<cfset VARIABLES.ppVals.signature = "x">
	<cfset VARIABLES.ppVals.version = "52">
	<cfset VARIABLES.ppVals.token = SESSION.user.token>
	<cfset VARIABLES.ppVals.payerid = SESSION.user.payerid>
	<cfset VARIABLES.ppVals.paymentaction = "Sale">
	<cfset VARIABLES.ppVals.amt = NumberFormat(session.totalBasketPrice + session.shipping, '___.__')>
	
	<!--- call the method to initiate the pp request --->
	<cfinvoke component="CallerService" method="doHttppost" requestdata="#VARIABLES.ppVals#" serverurl="https://www.paypal.com/uk/cgi-bin/webscr" returnvariable="VARIABLES.response">
	
	<!--- send data to method to return it as a struct --->
	<cfinvoke component="CallerService" method="getNVPResponse" nvpString="#URLDecode(VARIABLES.response)#" returnvariable="VARIABLES.responseStruct">
	
	<!--- make sure the transaction was finalized --->
	<cfif VARIABLES.responseStruct.ack eq "success">
		<!--- redirect the user to the order confirm page --->
		<cflocation url="https://www.joe-cool.co.uk/EN/basket2/order_confirmed.cfm?ppExp=true" addtoken="false">
	<cfelse>
		<!--- output an error message --->
		<p style="text-align:center;color:red;font-size:x-large;">Sorry. There was a problem connecting with the PayPal server.</p>
		<p style="text-align:center;"><!---<cfdump var="#VARIABLES.responseStruct#">---></p>
	</cfif>
</cfif>

Open in new window

0
Comment
Question by:adam1h
  • 8
  • 4
  • 2
  • +1
15 Comments
 
LVL 36

Expert Comment

by:SidFishes
ID: 38811214
Wild guess...have you tried using GET? That will submit all form variables as url values. Might be worth a try...
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 38811301
No, POST is required with Paypal.  You are still sending to the 'sandbox' in https://www.sandbox.paypal.com/ .  That is not the correct URL for a live site which is https://www.paypal.com/ .
0
 

Author Comment

by:adam1h
ID: 38811552
Hi SidFishes and DaveBaldwin,

@DaveBaldwin:
Thanks to point this to me.
I have corrected the url, but I still have the same issue :-(
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 38811821
I tried calling Paypal but I got no answer from any of the developer numbers.  For some reason, I keep thinking that the API credentials for the sandbox are not the ones you use for the live site.

However your error message comes from the web server before you even get to that part.  Have you gone back to the sandbox and made sure your code is still working there?
0
 

Author Comment

by:adam1h
ID: 38811841
Yes, it works fine in the sandbox
0
 

Author Comment

by:adam1h
ID: 38818329
Hi,

Well after many searches, I resolve this issue by adding a variable in the setExpressCheckout call :
<cfset VARIABLES.ppVals.SolutionType = "Mark">

Open in new window


But now I have another issue :
Error 11601 :  Request for billing address failed
Billing address request is not enabled for merchant

But it happens in the setExpressMethod call, so I don't understand, I don't ask for billing address !

Do you have an idea why it happens ?
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 38819612
No idea.  But I did get a response from Paypal saying that Sandbox credentials are not valid on the live site.  They didn't answer about where I needed to get the 'live' credentials.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:adam1h
ID: 38819642
Yes indeed, but I have changed credentials (user/password/signature). With the live ones.

Maybe the URL I use to connect to API and redirect user is wrong. But it's difficult to find a clear answer on the web.
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 38819696
It's difficult getting a clear answer from Paypal!!
0
 

Accepted Solution

by:
adam1h earned 0 total points
ID: 38839695
I have finally resolved this issue :

Some of the parameters were deprecated :
paymentAction is now PAYMENTREQUEST_0_PAYMENTACTION
amt is now PAYMENTREQUEST_0_AMT

And the url to redirect the customer to paypal is :
https://www.paypal.com/webscr?cmd=_express-checkout&token=#VARIABLES.responseStruct.token#
and not what I had
https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=#VARIABLES.responseStruct.token#

Now it rocks
0
 

Author Closing Comment

by:adam1h
ID: 38854284
As described in my last comment, I have found and resolved the errors on my code.
0
 

Expert Comment

by:CFDevv
ID: 39140325
Could you share your full working example as I'm trying to add Paypal Express Checkout to my shopping cart also.
0
 

Author Comment

by:adam1h
ID: 39141357
Hi,

This workflow is proper to our site and can be modified.

1st the user go to his details page where he select paypal.
2nd he go on a checkout page where the paypal transaction is initiate on the 1st run, ans on the 2nd one I retrieve his data from paypal.
3nd he go to an order_confirmed page where the transaction is performed.

Here is the code:
on checkout's head:
<!--- SetExpressCheckout --->
<cfif CGI.request_method eq "POST" AND isdefined("URL.ppExp") AND URL.ppExp eq "true">
	<!--- set our values to send to paypal into a struct --->
	<cfset VARIABLES.ppVals = structnew()>
	
	<cfset VARIABLES.ppVals.method = "SetExpressCheckout">
	<cfset VARIABLES.ppVals.PAYMENTREQUEST_0_PAYMENTACTION = "Sale">
	<cfset VARIABLES.ppVals.user = "blahblah">
	<cfset VARIABLES.ppVals.pwd = "blahblah">
	<cfset VARIABLES.ppVals.signature = "blahblah">
	<cfset VARIABLES.ppVals.version = "76.0">
	<cfset VARIABLES.ppVals.PAYMENTREQUEST_0_AMT = NumberFormat(session.totalBasketPrice + session.shipping, '___.__')>
	<cfset VARIABLES.ppVals.PAYMENTREQUEST_0_CURRENCYCODE = uCase(session.currency)>
	<cfset VARIABLES.ppVals.returnurl = "https://www.joe-cool.co.uk/EN/basket/checkout.cfm">
	<cfset VARIABLES.ppVals.cancelurl = "https://www.joe-cool.co.uk/EN/basket/shopping_basket.cfm">
	<cfset VARIABLES.ppVals.SolutionType = "Mark">
	
	<!--- call the method to initiate the pp request ---> <!--- test url = https://api-3t.sandbox.paypal.com/nvp --->
	<cfinvoke component="CallerService" method="doHttppost" requestdata="#VARIABLES.ppVals#" serverurl="https://api-3t.paypal.com/nvp" returnvariable="VARIABLES.response">
	
	<!--- send data to method to return it as a struct --->
	<cfinvoke component="CallerService" method="getNVPResponse" nvpString="#URLDecode(VARIABLES.response)#" returnvariable="VARIABLES.responseStruct">
	
	<!--- check if the connection with paypal was a success --->
	<cfif isdefined("VARIABLES.responseStruct.ack") AND VARIABLES.responseStruct.ack eq "success">
		<!--- send the user to paypal login --->
		<!---<cflocation url="https://api-3t.paypal.com/nvp/cgi-bin/webscr?cmd=_express-checkout&token=#VARIABLES.responseStruct.token#"  addtoken="false">--->
		<cflocation url="https://www.paypal.com/webscr?cmd=_express-checkout&token=#VARIABLES.responseStruct.token#"  addtoken="false">
	<cfelse>
		<!--- output an error message --->
		<p style="text-align:center;color:red;font-size:x-large;">Sorry. There was a problem connecting with the PayPal server.</p>
		<p style="text-align:center;"><cfdump var="#VARIABLES.responseStruct#"></p>
	</cfif>
</cfif>

<!--- GetExpressCheckoutDetails --->
<cfif isdefined("URL.token") AND isdefined("URL.PayerId")>
	<!--- set our values to send to paypal into a struct --->
	<cfset VARIABLES.ppVals = structnew()>
	
	<cfset VARIABLES.ppVals.method = "GetExpressCheckoutDetails">
	<cfset VARIABLES.ppVals.user = "blahblah">
	<cfset VARIABLES.ppVals.pwd = "blahblah">
	<cfset VARIABLES.ppVals.signature = "blahblah">
	<cfset VARIABLES.ppVals.version = "76.0">
	<cfset VARIABLES.ppVals.token = URL.token>
	
	<!--- call the method to initiate the pp request --->
	<cfinvoke component="CallerService" method="doHttppost" requestdata="#VARIABLES.ppVals#" serverurl="https://api-3t.paypal.com/nvp" returnvariable="VARIABLES.response">
	
	<!--- send data to method to return it as a struct --->
	<cfinvoke component="CallerService" method="getNVPResponse" nvpString="#URLDecode(VARIABLES.response)#" returnvariable="VARIABLES.responseStruct">
	
	<!--- if we get back the details set them into the user session --->
	<cfif isdefined("VARIABLES.responseStruct.ack") AND VARIABLES.responseStruct.ack eq "success">
		<cfset SESSION.user.countryCode = VARIABLES.responseStruct.countrycode>
		<cfset SESSION.user.email = VARIABLES.responseStruct.email>
		<cfset SESSION.user.firstName = VARIABLES.responseStruct.firstname>
		<cfset SESSION.user.lastName = VARIABLES.responseStruct.lastname>
		<cfset SESSION.user.payerid = VARIABLES.responseStruct.payerid>
		<cfset SESSION.user.payerstatus = VARIABLES.responseStruct.payerstatus>
		<cfset SESSION.user.shippingCountryCode = VARIABLES.responseStruct.shiptocountrycode>
		<cfset SESSION.user.shippingCountryName = VARIABLES.responseStruct.shiptocountryname>
		<cfset SESSION.user.shippingName = VARIABLES.responseStruct.shiptoname>
		<cfset SESSION.user.shippingCity = VARIABLES.responseStruct.shiptocity>
		<cfif isDefined("VARIABLES.responseStruct.shiptostate")> <cfset SESSION.user.shippingState = VARIABLES.responseStruct.shiptostate>
		<cfelse> <cfset SESSION.user.shippingState = "n/a"> </cfif>
		<cfset SESSION.user.shippingAddress = VARIABLES.responseStruct.shiptostreet>
		<cfset SESSION.user.shippingZipCode = VARIABLES.responseStruct.shiptozip>
		<cfset SESSION.user.token = VARIABLES.responseStruct.token>
		
		<!--- move the user to the billing and shipping page --->
		<!---<cflocation url="https://www.joe-cool.co.uk/EN/basket/checkout.cfm?ppDo=true" addtoken="false">--->
	<cfelse>
		<!--- output an error message --->
		<p style="text-align:center;color:red;font-size:x-large;">Sorry. There was a problem connecting with the PayPal server.</p>
		<p style="text-align:center;"><!---<cfdump var="#VARIABLES.responseStruct#">---></p>
	</cfif>
</cfif>

Open in new window


on checkout's body:
<cfif Session.ccard EQ "Paypal" AND NOT isdefined("URL.token") AND NOT isdefined("URL.PayerId")>
						<cfform name="ppExpForm" method="post" action="#CGI.SCRIPT_NAME#?ppExp=true">
							<!---<td> <input type="image" name="paypalSubmit" src="https://fpdbs.paypal.com/dynamicimageweb?cmd=_dynamic-image" alt="Paypal" border="0"> </td>---> 
							<td> <input type="image" name="submit" src="https://www.paypalobjects.com/en_GB/GB/i/btn/btn_xpressCheckout.gif" id="submit" runat="server" onclick="processing();"></td>
						</cfform>
					</cfif>

Open in new window


on orderconfirmed's head:
<!--- DoExpressCheckoutPayment --->
		<cfif isdefined("URL.ppDo") AND URL.ppDo eq "true">
			<!--- set our values to send to paypal into a struct --->
			<cfset VARIABLES.ppVals = structnew()>
			
			<cfset VARIABLES.ppVals.method = "DoExpressCheckoutPayment">
			<cfset VARIABLES.ppVals.user = "blahblah">
			<cfset VARIABLES.ppVals.pwd = "blahblah">
			<cfset VARIABLES.ppVals.signature = "blahblah">
			<cfset VARIABLES.ppVals.version = "76.0">
			<cfset VARIABLES.ppVals.token = SESSION.user.token>
			<cfset VARIABLES.ppVals.payerid = SESSION.user.payerid>
			<cfset VARIABLES.ppVals.PAYMENTREQUEST_0_PAYMENTACTION = "Sale">
			<cfset VARIABLES.ppVals.PAYMENTREQUEST_0_AMT = NumberFormat(session.totalBasketPrice + session.shipping, '___.__')>
			<cfset VARIABLES.ppVals.PAYMENTREQUEST_0_CURRENCYCODE = uCase(session.currency)>
			
			<!--- call the method to initiate the pp request --->
			<cfinvoke component="CallerService" method="doHttppost" requestdata="#VARIABLES.ppVals#" serverurl="https://api-3t.paypal.com/nvp" returnvariable="VARIABLES.response">
			
			<!--- send data to method to return it as a struct --->
			<cfinvoke component="CallerService" method="getNVPResponse" nvpString="#URLDecode(VARIABLES.response)#" returnvariable="VARIABLES.responseStruct">
			
			<!--- make sure the transaction was finalized --->
			<cfif VARIABLES.responseStruct.ack eq "success">
				<!--- redirect the user to the order confirm page --->
				<!---<cflocation url="https://www.joe-cool.co.uk/EN/basket/order_confirmed.cfm?ppExp=true" addtoken="false">--->
			<cfelse>
				<!--- output an error message --->
				<p style="text-align:center;color:red;font-size:x-large;">Sorry. There was a problem connecting with the PayPal server.</p>
				<p style="text-align:center;"><!---<cfdump var="#VARIABLES.responseStruct#">---></p>
			</cfif>
		</cfif>

Open in new window

0
 

Author Comment

by:adam1h
ID: 39141362
Hope it helps :-)
0
 

Expert Comment

by:CFDevv
ID: 39170277
So the first page is the one that makes the call to Paypal once they have selected paypal and click next on the cart.

The third one is the return url confirming the payment.

Just to confirm, what is the second page doing?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
How important is it to take extra precautions to protect your online business? These are some steps you can take to make sure you're free of any cyber crime.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now