Skip to content

Instantly share code, notes, and snippets.

@marchbold
Last active August 29, 2015 14:24
Show Gist options
  • Save marchbold/a0e077c120f424568ea6 to your computer and use it in GitHub Desktop.
Save marchbold/a0e077c120f424568ea6 to your computer and use it in GitHub Desktop.
Obtaining consent for future payments with the PayPal SDK
if (PayPalSDK.isSupported)
{
PayPalSDK.service.addEventListener( PayPalFuturePaymentEvent.COMPLETE, paypal_futurePaymentCompleteHandler );
PayPalSDK.service.addEventListener( PayPalFuturePaymentEvent.CANCELLED, paypal_futurePaymentCancelledHandler );
PayPalSDK.service.addEventListener( PayPalFuturePaymentEvent.ERROR, paypal_futurePaymentErrorHandler );
if (PayPalSDK.service.connect( PayPalEnvironment.NO_NETWORK ))
{
PayPalSDK.service.obtainConsentForFuturePayment();
}
}
...
private function paypal_futurePaymentCompleteHandler( event:PayPalPaymentEvent ):void
{
trace( "payment complete" );
trace( "authorisation code = " + event.auth.code );
trace( "clientMetadataID = " + PayPalSDK.service.getClientMetadataID() );
// TODO:
// Send the authorization response to your server, where it can exchange the authorization code
// for OAuth access and refresh tokens.
//
// Your server must then store these tokens, so that your server code can execute payments
// for this user in the future.
}
private function paypal_futurePaymentCancelledHandler( event:PayPalPaymentEvent ):void
{
trace( "payment cancelled" );
}
private function paypal_futurePaymentErrorHandler( event:PayPalPaymentEvent ):void
{
trace( "payment error" );
}
// com.distriqt.PayPalSDK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment