Add PayPal payment in Flex / AIR

March 19 2008 by Julien Lestel

Here is a sample code to add the button PayPal "buy now" in your development Adobe Flex.

paypal flex

see example

This movie requires Flash Player 9

This code can be improved to make a basket to send to paypal in Flex. The method sends the data to paypal with a redirect button "buy now" using flash.net.URL request. The example is basic, and full management of the basket is a long ...

Now the sources:

Typical HTML file for the call to PayPal:

<! DOCTYPE html PUBLIC "- / / W3C / / DTD XHTML 1.0 Transitional / / EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> Untitled Document </ title>
</ head>

<body>
<form method="post"> action="https://www.paypal.com/cgi-bin/webscr"
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="you@youremail.com">
<input type="hidden" name="item_name" value="Item Name">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="amount" value="0.00">
<input type = "image" src = "http://www.paypal.com/en_US/i/btn/x-click-but01.gif" name = "submit" alt = "Make payments with PayPal - it's fast, free and secure! ">
</ form>
</ body>
</ html>

And here is the Flex:

<xml version = "1.0" encoding = "utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

<mx: Image source = "http://www.paypal.com/en_US/i/btn/x-click-but01.gif" horizontalCenter = "0" verticalCenter = "0" click = "makePayment ();"/ >
<mx:Script>
<[CDATA [
import flash.net.URLRequest
public function makePayment (): void (
var url: String = "https: / / www.paypal.com / cgi-bin / webscr";
var request: URLRequest = new URLRequest (url);
var variables: URLVariables = new URLVariables ();
variables.cmd = "_xclick";
variables.currency_code = "EUR";
variables.business = "contact@flex-info.fr";
variables.item_number = "001";
variables.item_name = "Donation for Flex-info.fr";
variables.amount = "1.00";
variables.quantity = 1;
variables.tax ='';
request.data = variables;
request.method = URLRequestMethod.POST;
navigateToURL (request, "_parent");
)
]]>
</ mx: Script>
</ mx: Application>

To embed this button on a list of products:

1) load product data from a xml file and a call with HTTPService

2) Use the "repeater" to create your buttons (and the product display)

... And implement it in your shopping cart to pay with PayPal!

Hoping that this helps some of you :)
Note: This procedure applies to implement most of the online payments :)
Source: Community Flex

If you come for the first time on Flex-info.fr, you can subscribe to the RSS feed. Thank you for your visit!

1 étoile2 étoiles3 étoiles4 étoiles5 étoiles (1 votes, 5.00 out of 5)
Loading ... Loading ...

12 comments on this post

  1. jeanphilippe Says:

    hi
    thank you for this very useful example :)

  2. Yann Rusty Says:

    Hi,

    Very interesting example of this PayPal! Thank you very much.

  3. Arnaud Says:

    Great!
    Thank you for this example.

  4. Florian Says:

    So it sure is easy to implement but it can bring other problems where one wants to retrieve the result of the transaction, for example, where delivering a product purchased by a customer .

    From the moment you want to retrieve the result of the transaction, you lose the status of implementation because the swf must be reloaded when switching SWF> Paypal or Paypal> SWF. So we must find a way to reload the application in the same condition it was before being redirected to paypal which can become quite difficult to implement depending on the complexity of the application.

  5. Florian Says:

    It is true that it seems easy to integrate at first sight, but this article does not explain the most difficult to implement, namely the recovery of the outcome of the request.

    When using Paypal, we want généralemet how the transaction took place the customer's paypal page. For example, to update its stock in the future or simply retrieve the delivery address.

    To do this, you must specify in the script, a variable 'return' that indicates the URL of return, namely that of the SWF. The SWF is reloaded must at one time or another (either in the transition from application to paypal or to return). The problem is that the status of implementation is lost and must be put in place a system to recover this state at the time of return which can be difficult depending on the complexity of the application. (For example, for an application that contains several tabs, these tabs display as well as their content)

  6. Florian Says:

    > Sorry for the comment too. My computer crashed at the time of posting the 1st comment and I thought it was not passed

  7. Manuel Says:

    Hello Julien,

    We have 2 sites on integrated payment without going through the open window or HTML page, which is simpler and more reassuring for the user. We will try to take the time to do a story on http://www.matsiya.fr ;)
    + +

  8. Julien Says:

    Ok, let us keep abreast :)

  9. MrBark Says:

    hello! this c code can be improved to make a basket to send a paypal flex :) precision necessary? n the parenthèsese sometimes say more than Toutle e rest :) billlet thank you for this interesting, fun to read vou!

  10. nourrain Says:

    hi,

    Indeed, it would be nice to know how to send a request basket paypal "without opening a new window. Just by sending data at Paypal but remaining on the current page.

    Thank you

    Mr Nourrain

  11. Goel Says:

    Hello,

    I just want to give some details on the integration process a payment in a flash / flex.

    For now, the only way for the customer not to leave the environment of the site is the communication server (your server and the trusted third party).

    API paypal (express) is not possible at this time because the customer is leaving at some point the environment.

    Some trusted third party service provides communication between servers but is more expensive than traditional service.

    Ex: Direct PayBox Services.

    Sincerely yours
    Goel

  12. Julien Lestel Says:

    Ok noted. Goel thank you for the info :)

1 Trackbacks This artic

  1. Creation »Blog Archive» Add the PayPal payment in Flex / AIR Says:

    [...] Http://www.flex-info.fr/ajouter-le-paiement-paypal-dans-flex-air/20080319/ [...]

Write a comment

Subscriptions

  • Add to My AOL
  • Add to Google
  • Add to Zune
  • Add to Netvibes
  • Add to Technorati
  • Add to My Yahoo
  • Add to Zune

Survey

How do you find the new Flex-info.fr?

View Results

Loading ... Loading ...

Mugsho