Methods For Integrating Digital Goods Into Flash

Note: Express Checkout Digital Goods is no longer available for new integrations. This feature remains available for merchant accounts that already have Express Checkout Digital Goods enabled.

You can integrate digital goods into a Flash file.

Integrating Digital Goods With Flash

The following is an example of how a first-party merchant can integrate digital goods with Flash.

To integrate digital goods with Flash:

  1. Include the digital goods JavaScript library in the HTML page game.html, which also includes the Flash movie game.swf.

  2. Include the following ActionScript in the Flash movie game.swf to initialize the digital goods object:

    dg_button.addEventListener(
    MouseEvent.MOUSE_UP,
    function(evt:MouseEvent):void {
    var payment_URL:String = "<Merchant URL to initiate API call>";
    // use ExternalInterface to call the JavaScript method dg.startFlow
    var result:uint =
    ExternalInterface.call("dg.startFlow",payment_URL);
    }
    );
    function paymentComplete(responseText):void {
    // use responseText to do any customizations
    }
    // register the callback method so it can be called via JavaScript
    ExternalInterface.addCallback("paymentCompleteExt", paymentComplete);
    

Integrating Digital Goods With Flash - Third-Party Merchant

The following is an example of how a third-party merchant can integrate digital goods with Flash.

In the following example, use ActionScript 3.0's LocalConnection in the Flash movie, game.swf, to respond to the payment.

  1. Create the Flash movie, game.swf, with the following code. The code assumes the button click on dg_button initiates payment.

    // create local connection
    var conn:LocalConnection;
    conn = new LocalConnection();
    // allow cross domain connection
    conn.allowDomain('*');
    // identify this movie as the receiver (i.e. client)
    conn.client = this;
    
    dg_button.addEventListener(
    MouseEvent.MOUSE_UP,
    function(evt:MouseEvent):void {
    // following URL will begin the DG API call
    var payment_URL:String =
    "<Merchant URL to initiate API call>";
    
    // following JS opens a new window to the appropriate size
    // for DG checkout
    var jscommand:String =  "window.open('"+payment_URL+"','win',
    'height=550,width=400,toolbar=no,scrollbars=no');";
    var url:URLRequest = new URLRequest("javascript:" +
    jscommand + "
    void(0);");
    navigateToURL(url, "_self");
    
    //initiate listening on connection
    conn.connect('paymentConn');
    });
    function paymentComplete(responseText):void {
    //use responseText to do any customizations
    //close the LocalConnection
    conn.close();
    }
    
  2. Specify another Flash movie, return.swf, as the return URL in the API call.

  3. Use FlashVars or ExternalInterface in return.swf to gather any required values from the API response.

  4. Use the LocalConnection from step 1 in return.swf to communicate with game.swf, for example:

    var sendingLC:LocalConnection = new LocalConnection();
    // do anything required to get API response parameters into
    // the "response" variable
    // connect to game.swf and call paymentComplete
    sendingLC.send('paymentConn', 'paymentComplete', response);