Skip to content

Instantly share code, notes, and snippets.

@jasonhuck
Created November 5, 2010 10:13
Show Gist options
  • Select an option

  • Save jasonhuck/663918 to your computer and use it in GitHub Desktop.

Select an option

Save jasonhuck/663918 to your computer and use it in GitHub Desktop.

Revisions

  1. jasonhuck created this gist Nov 5, 2010.
    76 changes: 76 additions & 0 deletions Lasso PayPal Express Checkout
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,76 @@
    --- Include this at the top of every page, e.g., [library('config.inc')]. ---
    [//lasso
    // include required tags
    // (these could also be loaded via LassoStartup)
    library('tags/dictionary.inc'); // http://tagswap.net/dictionary
    library('tags/paypal_nvpapi.inc');

    // create a new paypal object to work with
    var('pp') = paypal_nvpapi(
    -pwd='your-api-password',
    -user='your-api-username',
    -signature='your-api-signature',
    -test=true // use the sandbox server
    );
    ]

    -- Process a user-submitted form with Express Checkout. ---
    [//lasso
    // include standard configuration.
    library('config.inc');

    // call the SetExpressCheckout method
    // the [$response] variable will contain all of the
    // parameters returned by PayPal, which you can
    // access as member tags, e.g., [$response->foo]
    var('response') = $pp->SetExpressCheckout(
    -paymentaction='Authorization',
    -amt='19.95',
    -returnurl='your-return-url',
    -cancelurl='your-cancel-url'
    );

    // if the operation was successful...
    if($response->ack >> 'Success');
    // send the user to PayPal with the token you just got back
    redirect_url('https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=' + $response->token);
    else;
    'Could not continue due to an error.';
    /if;
    ]

    -- User completes transaction and is redirected to your-return-url by PayPal. ---
    [//lasso
    // include standard configuration.
    library('config.inc');

    // if the token param was passed to the page...
    if(action_param('token'));
    // set it to a variable
    var('token') = action_param('token');

    // call the GetExpressCheckoutDetails method
    var('response') = $pp->GetExpressCheckoutDetails( -token=$token);

    // if the operation was successful...
    if($response->ack >> 'Success');
    // complete the transaction by calling the DoExpressCheckoutPayment method
    var('response') = $pp->DoExpressCheckoutPayment(
    -paymentaction='Authorization',
    -payerid=$response->payerID,
    -amt='19.95',
    -token=$token
    );

    if($response->ack >> 'Success');
    'Transaction successful!';
    else;
    'Transaction could not be completed due to an error.';
    /if;
    else;
    'Could not continue due to an error.';
    /if;
    else;
    'No token was passed to the page.';
    /if;
    ]