Setting paypal for mobile - jquery-mobile

I have created paypal button with this code
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<!-- Order id. -->
<input type="hidden" name="invoice" value="'+paypalData.orderId+'" />
<!-- Specify a PayPal Shopping Cart Add to Cart button. -->
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<!-- Identify your business so that you can collect the payments. -->
<input type="hidden" name="business" value="'+paypalData.businessId+'">
<!-- Specify currency. -->
<input type="hidden" name="currency_code" value="'+paypalData.currency+'">
<!-- The URL to which PayPal posts information about the payment, in the form of Instant Payment -->
<input type="hidden" name="notify_url" value="notify">
<!-- Return URL when cancel payment -->
<input type="hidden" name="cancel_return" value="cancel">
<!-- Return URL when payment is done -->
<input type="hidden" name="return" value="return">
<input type="hidden" name="amount_'+index+'" value="'+val["price_per_unit"]+'">
<input type="hidden" name="quantity_'+index+'" value="'+val["count"]+'">
<input type="hidden" name="item_name_'+index+'" value="'+val["name"]+'">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="'+paypalData.submitAlt+'">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
But I need to modify it for jQuery mobile. I know that I have to use this command:
cmd=_express-checkout-mobile in url https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout-mobile
but I dont know how to use it and where to put it.
Whole aplication is converted by phonegap.
Thank you very much for your time and any advice.

Your current integration is using PayPal Standard. Express Checkout is part of the API products. You would need to rebuild your checkout using the API to take advantage of Express Checkout.

Related

How to convert HTML form to C# for PayPal subscription

I have the following HTML which works well for subscription payments in my test environment.
<form action="paypalWebAddress" method="post" target="_top">
<input type="hidden" name="cmd" value="_xclick-subscriptions"/>
<input type="hidden" name="business" value="myPaypalAccountId"/>
<input type="hidden" name="paymentaction" value="sale"/>
<input type="hidden" name="item_name" value="Subscription For abc123"/>
<input type="hidden" name="currency_code" value="GBP"/>
<input type="hidden" name="no_note" value="1" />
<input type="hidden" name="a3" value="50"/>
<input type="hidden" name="p3" value="6"/>
<input type="hidden" name="t3" value="M"/>
<input type="hidden" name="src" value="1" />
<input type="hidden" name="srt" value="0" /><!--needs to be never ending-->
<input type="hidden" name="return" value="www."/>
<input type="hidden" name="notify_url" value="www."/>
<input type="hidden" name="cancel_url" value="www."/>
<input type="hidden" name="custom" value="abc123"/>
<input TYPE="hidden" name="charset" value="utf-8">
<input type="hidden" name="bn" value="Me_Subscribe_WPS_UK" />
<input type="submit" name="submit" value="Make Payment"/>
</form>
I'm about to go live and concerned that some one could easily manipulate the DOM and I'm suddenly sending bogus payments. I feel it would be safer to somehow post these values from the code behind so the user can't tamper with the values but, the user will still need to use the PayPal interface in their browser to log in and subscribe.
PayPal-NET-SDK has a quick start and shows how to get going. I have completed this (copied and pasted and ran in debug mode) and it executes fine. However, this doesn't cover subscriptions, probably for the reason explained above (and would probably prevent them accessing the PayPal gui in their browser).
I get the option in the PayPal dashboard area to create a button and reference by button, but, this won't work for me as I need to be able to set the custom field per subscription as a user can subscribe to 1 or more services and each service is unique to that user.
I can't understand how to achieve this
If I understand this right, every subscription is unique per customer in your case and that won't work with the static buttons, so the API seems the only way to go.
The PayPal API does cover subscriptions, they're called Billing Plans. Because each subscription is different, you could create a new Billing Plan for each unique service (or combination of services). This can be done without any intermediate SDK using the HttpClient directly to their API.
Alternatively, the PayPal-NET-SDK you mentioned also seems to cover Billing plans. Their Sample application has quite a lot of examples on how to create, enumerate and issue Billing Plans. Make sure you check out the billing_agreement_tokens collection on the Payment class. You might add multiple "service" tokens there.
No matter how close you are to releasing, a lot of testing still seems to be in order here.
You can try using HttpClient, something like this will help
HttpContent content = new FormUrlEncodedContent(
new List<KeyValuePair<string, string>> {
new KeyValuePair<string, string>("key1",
"value1"),
new KeyValuePair<string,string>("key2","value2")
});
content.Headers.ContentType = new
MediaTypeHeaderValue("application/x-www-form-
urlencoded");
content.Headers.ContentType.CharSet = "UTF-8";
HttpResponseMessage resposne = await
client.PostAsync(new Uri("paypalWebAddress"),
content);
You should not hardcode the values in forms, instead you should create an API in the backend which will return the correspoding values.Then you can dynamically create the form based on the response of the API.
Make sure you create this form after you have received the response from the API.You can have a check like if response is null show some spinner.
<form action="paypalWebAddress" method="post" target="_top">
<input type="hidden" name="cmd" value="{response.cmd}"/>
<input type="hidden" name="business" value={response.business}"/>
<input type="hidden" name="paymentaction" value={response.action}/>
<input type="hidden" name="item_name" value="{response.item}"/>
<input type="submit" name="submit" value="Make Payment"/>
</form>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="business.test.com">
<input type="hidden" name="item_name" value="Memory Stick">
<input type="hidden" name="item_number" value="MEM32507725">
<input type="hidden" name="amount" value="3">
<input type="hidden" name="tax" value="1">
<input type="hidden" name="quantity" value="1">
<input type="hidden" name="currency_code" value="USD">
<!-- Enable override of buyers's address stored with PayPal . -->
<input type="hidden" name="address_override" value="1">
<!-- Set variables that override the address stored with PayPal. -->
<input type="hidden" name="first_name" value="John">
<input type="hidden" name="last_name" value="Doe">
<input type="hidden" name="address1" value="345 Lark Ave">
<input type="hidden" name="city" value="San Jose">
<input type="hidden" name="state" value="CA">
<input type="hidden" name="zip" value="95121">
<input type="hidden" name="country" value="US">
<input type="image" name="submit"
src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif"
alt="PayPal - The safer, easier way to pay online">
</form>
On Click on buy now :
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<!-- Identify your business so that you can collect the payments. -->
<input type="hidden" name="business" value="herschelgomez#xyzzyu.com">
<!-- Specify a Buy Now button. -->
<input type="hidden" name="cmd" value="_xclick">
<!-- Specify details about the item that buyers will purchase. -->
<input type="hidden" name="item_name" value="Premium Umbrella">
<input type="hidden" name="amount" value="50.00">
<input type="hidden" name="currency_code" value="USD">
<!-- Prompt buyers to enter the quantities they want. -->
<input type="hidden" name="undefined_quantity" value="1">
<!-- Display the payment button. -->
<input type="image" name="submit" border="0"
src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif"
alt="Buy Now">
<img alt="" border="0" width="1" height="1"
src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" >
</form>

How to dynamically generate a PayPal button with Rails?

I have an e-commerce website with many different products with different prices, and I want to allow people to buy them using PayPal. This guide details how to create a PayPal Buy Now button, but you have to manually fill out a form. This would be very very time consuming to do every time I add a product.
I looked at the HTML of the Buy Now button, hoping to be able to inject my product information with ERB, but nowhere in the HTML is the product information like price listed. Instead, there's a very long "value" element, and I assume the product information is encrypted within this.
Anyone know how to dynamically generate a PayPal button with Rails? If not, does anyone know of am alternative I could use?
You can inject the data as below:
ERB sample (in case you are sending one product):
<li>
<b>product name:</b> <%= #product.name %>
<br>
<b>product price:</b> <%= #product.price %>
<b style='text-decoration: underline;'>Pay:</b>
<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post" >
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="yourbusinessmail#hotmail.com*">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="item_name" value="<%= #product.name %>">
<input type="hidden" name="item_number" value="<%= #product.id %>">
<input type="hidden" name="amount" value="<%= #product.price %>">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="button_subtype" value="products">
<input type="hidden" name="no_note" value="0">
<input type="hidden" name="shipping" value="<%= #product.shipping %>">
<input type="hidden" name="add" value="1">
<input type="hidden" name="bn" value="PP-ShopCartBF:btn_cart_LG.gif:NonHostedGuest">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_cart_LG.gif" border="0" name="submit" >
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
</li>
Use below Paypal website link to customize your button then you can inject values as in Ruby code:
Design Paypal button

How do I setup Auto Return URL for a PayPal Buy Button?

I am using the html code for a simple Paypal buy button but was wondering if it's possible to setup an auto return url without having to do it through my own Paypal account itself?
I can't do it that way because it is a localhost website (cannot validate a real website) and I'm not creating a button through my selling tools.
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<!-- Identify your business so that you can collect the payments. -->
<input type="hidden" name="business" value="email#email.com">
<!-- Specify a Buy Now button. -->
<input type="hidden" name="cmd" value="_xclick">
<!-- Specify details about the item that buyers will purchase. -->
<input type="hidden" name="item_name" value="Demo">
<input type="hidden" name="amount" value="0.01">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="return" value="~/">
<!-- Display the payment button. -->
<input type="image" name="submit" border="0" src="https://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif" alt="PayPal - The safer, easier way to pay online">
<img alt="" border="0" width="1" height="1" src="https://www.paypal.com/en_US/i/scr/pixel.gif">
</form>
Yes you can set your own return URL. HTML Special Variables. You can add this code to your form.
<input type="hidden" name="return" value="http://localhost" />
In your html you are defining a relative path to your home directory but you will need an HTTP or HTTPS url for it to work. This is because the page that the paypal checkout is on is not in your root directory, so it needs a specific location.

How to return with POST after PayPal billing?

I created the next form:
<form name="_xclick" action="https://www.sandbox.paypal.com/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="team#team.com">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="item_name" value="Subscription">
<input type="hidden" name="return" value="http://www.my_website.com/<%= params[:locale] %>/success">
<input type="hidden" name="amount" value="1">
<input type="image" src="http://www.paypal.com/en_US/i/btn/btn_paynow_LG.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>
But it redirects to my website via GET request. How can I redirect to my website via POST request after payment?
When I create my button in PayPal button factory:
<form action="https://www.sandbox.paypal.com/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="SOME_VALUE">
<input type="image" src="https://www.paypalobjects.com/en_US/IL/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
When I click on the PayPal button, I have set up success and cancel redirects when I click on the PayPal button, but the following error is displayed:
PayPal cannot process this transaction because of a problem with the seller's website. Please contact the seller directly to resolve this problem.
So, how can I change my first code that it will perform a POST redirect after billing?
Can you please check "https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/Appx_websitestandard_htmlvariables/"
and "rm" variable for solutions. And also set the hidden fields values for the paypal payment submissions.

Paypal return variables on success page

WHAT I AM TRYING TO DO
I am simply trying to display the results of a Paypal subscription signup. I see the issue of not being able to see the POST variables is a common issue.
I have tried many different ways to do this and I see a common solution is to use:
<input id="rm" name="rm" type="hidden" value="2">
This does not work.
I have tried emailing myself $_POST and $_REQUEST variables and they are empty.
However, my code that detects the txn_type $_POST variable works, since my variables appear in my database. After writing to the database, it is supposed to show a receipt, but does not.
Here's the button code:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<!-- Identify your business so that you can collect the payments. -->
<input type="hidden" name="business" value="paypalemail#gmail.com">
<!-- Specify a Subscribe button. -->
<input type="hidden" name="cmd" value="_xclick-subscriptions">
<!-- Identify the subscription. -->
<input type="hidden" name="item_name" value="Monthly Featured Listings">
<input type="hidden" name="item_number" value="1">
<!-- Set the terms of the regular subscription. -->
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="a3" value="0.01">
<input type="hidden" name="p3" value="1">
<input type="hidden" name="t3" value="M">
<input type="hidden" name="rm" value="2">
<!-- Set recurring payments until canceled. -->
<input type="hidden" name="src" value="1">
<input name="notify_url" value="http://www.example.com/user/register/index.php" type="hidden">
<input name="return" value="http://www.example.com/user/register/index.php" type="hidden">
<input name="cancel_return" value="http://www.example.com/user/register/index.php?payment=cancelled" type="hidden">
<!-- Display the payment button. -->
<input type="image" name="submit" border="0" src="http://www.example.com/images/register-and-pay-now.png" alt="PayPal - The safer, easier way to pay online">
<img alt="" border="0" width="1" height="1" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif">
Since my database code works, I can only guess that Paypal is sending the information correctly, but I can't get it to show up in the web page.
My QUESTION
How can I show successful $_POST variables in my page after the redirect?
Well, my guess is that the variables that you are receiving and storing to the database are hitting the notify_url.
These variables are the IPN variables and are not supposed to be shown on any web page.
In order to get information on the specified return URL you have to access the PDT data.
Read more about PDT here

Resources