Developer's Guide

Table Of Contents
Introducing Adaptive Payments
Embedded Payments
56 August 7, 2012 Adaptive Payments Developer Guide
1. Call the Pay API operation to obtain a valid pay key.
2. Create your form or button.
You must include the pay key and redirect to
https://www.paypal.com/webapps/adaptivepayment/flow/pay.
Optionally, include a preapproval key if you want to enable the selection of Preapproval
for future payments
Specify that a lightbox opens in the PayPal-created IFRAME, PPDGFrame.
Set the expType parameter to indicate your preference for the context in which the
PayPal payment flow is displayed. You must specify light for lightbox.
<form action=
"https://www.paypal.com/webapps/adaptivepayment/flow/pay"
target="PPDGFrame">
<input id="type" type="hidden" name="expType" value="light">
<input id="paykey" type="hidden" name="paykey" value="AP-..."> <input
id="preapprovalkey" type="hidden" name="preapprovalkey" value="PA-...">
<input type="submit" id="submitBtn" value="Pay with PayPal"> </form>
NOTE: To modify an existing application to use the embedded payment flow, change the
redirect from
https://www.paypal.com/webscr?cmd=_ap-payment&paykey=... to
https://www.paypal.com/webapps/adaptivepayment/flow/pay?
paykey=... after obtaining the pay key.
3. Include the PayPal JavaScript functions from dg.js.
<script src="https://www.paypalobjects.com/js/external/dg.js">
</script>
4. Create an embedded flow object and associate it with your payment form or button.
<script>
var dgFlow = new PAYPAL.apps.DGFlow({ trigger: 'submitBtn' });
</script>
After Completing This Task:
On the pages you identify as the return and cancel URLs in the Pay API operation, you must
include the PayPal JavaScript functions from dg.js and close the PayPal window, as in the
following example:
dgFlow = top.dgFlow || top.opener.top.dgFlow;
dgFlow.closeFlow();
top.close();