Link to home
Start Free TrialLog in
Avatar of adam1h
adam1hFlag for Belgium

asked on

Paypal Express -

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

Avatar of SidFishes
SidFishes
Flag of Canada image

Wild guess...have you tried using GET? That will submit all form variables as url values. Might be worth a try...
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/ .
Avatar of adam1h

ASKER

Hi SidFishes and DaveBaldwin,

@DaveBaldwin:
Thanks to point this to me.
I have corrected the url, but I still have the same issue :-(
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?
Avatar of adam1h

ASKER

Yes, it works fine in the sandbox
Avatar of adam1h

ASKER

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 ?
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.
Avatar of adam1h

ASKER

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.
It's difficult getting a clear answer from Paypal!!
ASKER CERTIFIED SOLUTION
Avatar of adam1h
adam1h
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of adam1h

ASKER

As described in my last comment, I have found and resolved the errors on my code.
Avatar of CFDevv
CFDevv

Could you share your full working example as I'm trying to add Paypal Express Checkout to my shopping cart also.
Avatar of adam1h

ASKER

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

Avatar of adam1h

ASKER

Hope it helps :-)
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?