Presentation from the Salesforce Developers meetup at Salesforce campus on April 1st - this presentation shows how the new PayPalX Toolkit makes payments easy in Salesforce. Force.com for PayPal X Payments Platform is a set of Apex classes for accessing the PayPal Adaptive Platform APIs. The toolkit is open source and available as a Code Share Project.
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Payments made easy on Force.com
1. Payments made Easy On Force.com Praveen Alavilli Developer Evangelist, PayPal @ppalavilli Salesforce Developer Meetup 4/1/2010
2. What ? A natural language processor that generates payments processing code based on human language What languages we support ? English Spanish French Hindi
14. PayPal The Sender A person or business whose PayPal account is being credited A person or business whose PayPal account is being debited C The Receiver The API CALLER The API access account who makes the Adaptive Payments service calls: usually owned by the developer Actors Involved
45. Allows an API caller to make payments on behalf of a sender within the constraints specified
46. PIN optional for future payments made within the authorized amount
47. Useful for single/multi use, and subscription paymentsC Pre Approval Sample Use Cases: Pay as you use, Micropayments for Digital goods, Subscriptions
56. Sample Interaction Flow A Rental App that allows tenants to pay rent to a property management that splits the payment to the actual owner and the HOA.
57. API WEB Sender Rental App Pay API Pay Key Redirect User to PayPal Return URL User Name = Rental_admin.api Secondary Receiver [2] = Sec Receiver_2@mail.com Password = keep$secret Amount = 50.00 Signature = 23KJHO5AS09I32SDROR Tracking ID = 234235986 Sender Email = john_m@mail.com Cancel URL = www.PayRent.com/home Currency = USD Return URL = www.PayRent.com/apstore Primary Receiver [0] = Prim Receiver@mail.com Amount = 1000.00 Secondary Receiver [1] = Sec Receiver_1@mail.com Amount = 40.00 Request IPN= https://www.Rental.com/IPN Sender Email: john_m@mail.com Receiver Email: PrimReceiver@paypal.com Pay Key = PA-84HK2A57FCOP3RW Response Notification Confidential and Proprietary 18 Confidential and Proprietary 18
58.
59. Account created can be used with any PayPal APIs, including Adaptive Payment APIs
66. Use cases for Adaptive Accounts As part of new employee enrollment, business collects information used to create a PayPal account Small Business As part of the onboarding for a buyer and seller, a PayPal account can be created so that the user experience can be localized and personalized Marketplace Create PayPal accounts to enable payments for games, social networking widgets and more Social Media 21
67. PayPal Development Process Submit for application review Get API credentials Go Live Design and build application Create Sandbox account Get APP ID Signup on x.com
98. Handle the response objectif(payResponse.PaymentExecStatus.equalsIgnoreCase('Created') ) { // send user to paypal for confirmation } else if(payResponse.PaymentExecStatus.equalsIgnoreCase('Completed') ) { // success } else { /*handle error */ }
99. Code Samples – Simple Payment // create request envelope and set the common request parameters object name PPPayRequest request = newPPPayRequest('MyRequestParams', paypalSenderId); // set success and cancel urls request.CancelUrl = 'https://' + host + '/StoreFront?status=cancel'; request.ReturnUrl = 'https://' + host + '/StoreFront?status=success'; // set a note associated with the payment request.Memo = message; // set Receiver info List<PPReceiver> receiverList = new List<PPReceiver>(); PPReceiver receiver1 = newPPReceiver(); // set the receiver email (receiver's PayPal Id) receiver1.email = paypalReceiverId; // set amount to be credited to the receiver's account receiver1.amount = amount; receiverList.Add(receiver1); // set receiver info in the request request.receiverList = receiverList; // create the Adaptive Toolkit object instance w/ API Credentials PPAdaptiveToolkit toolkit = newPPAdaptiveToolkit('SandboxCert'); try { // send the PayRequest using the Adaptive toolkit object PPPayResponse response = toolkit.pay(request); // check the response payment status if ( response.PaymentExecStatus.equalsIgnoreCase('Created') ) { // payment status is 'Created' - send the user to approval page returnPage= toolkit.commitpayment(response.payKey); } elseif( response.PaymentExecStatus.equalsIgnoreCase('Completed') ) { // the payment is 'Completed' (when no approval is required // - returned in case of pre-approvals or implicit approvals) // send the user to the return url returnPage = newpagereference(request.returnUrl); } returnreturnPage; } catch(PPFaultMessageExceptionfaultMsg) { /* handle errors */}
100. Code Sample – Chained/Parallel Payment PPReceiverreceiver1 = newPPReceiver(); // set the receiver email (receiver's PayPal Id) receiver1.email = paypalReceiverId1; // set amount to be credited to the receiver's account receiver1.amount = amount1; // set the primary flag to indicate if it’s a chained (true) or parallel (false) payment receiver1.Primary = true; receiverList.Add(receiver1); PPReceiverreceiver2 = newPPReceiver(); // set the receiver email (receiver's PayPal Id) receiver1.email = paypalReceiverId2; // set amount to be credited to the receiver's account receiver1.amount = amount2; receiverList.Add(receiver2); // set receiver info in the request request.receiverList = receiverList;
101. Code Sample – Preapprovals // create request envelope and set the common request parameters object name PPPreapprovalRequestrequest = newPPPreapprovalRequest ('MyRequestParams', paypalSenderId); // set success and cancel urls request.CancelUrl = 'https://' + host + '/StoreFront?status=cancel'; request.ReturnUrl = 'https://' + host + '/StoreFront?status=success'; // set a note associated with the payment request.Memo = message; // set Date of Month when the payment can be made using this preapproval request.DateOfMonth = 1; // set Day of week when the payment can be made using this preapproval request.DayOfWeek = 'WEDNESDAY'; // set the end date request.EndingDate = DateTime.newInstance(2010, 12, 31); // set the max amount per payment request.MaxAmountPerPayment = 10; // set max number of payment made using this preapproval request.MaxNumberOfPayments = 5; // set max number of payments made using this preapproval per period request.MaxNumberOfPaymentsPerPeriod = 1; // set max total payments using this preapproval request.maxTotalAmountOfAllPayment = 100; // set the payment period request.PaymentPeriod = 'DAILY'; // set a request pin to be associated with the preapproval request.PinType = ‘REQUIRED'; // or NOT_REQUIRED request.StartingDate = DateTime.newInstance(2009, 11, 8); // create the Adaptive Toolkit object instance w/ API Credentials PPAdaptiveToolkit toolkit = newPPAdaptiveToolkit('SandboxCert'); try { // send the PayRequest using the Adaptive toolkit object PPPayResponse response = toolkit.preapproval(request); // check the response payment status if ( response.PaymentExecStatus.equalsIgnoreCase('Created') ) { // if the payment status is 'Created' - send the user to approval page returnPage= toolkit.commitpreapproval(response.payKey); } elseif( response.PaymentExecStatus.equalsIgnoreCase('Completed') ) { // if the payment is 'Completed' (when no approval is required // - returned in case of pre-approvals or implicit approvals) // send the user to the return url returnPage = newpagereference(request.returnUrl); } returnreturnPage; } catch(PPFaultMessageExceptionfaultMsg) { /* handle exceptions */ }
102. Going Live Upgrade to a PayPal Business Account Get Verified Obtain Live API Credentials Submit App on X.com for review Follow the Salesforce “How to Publish” guide.
As a developer, the sender and receiver may have many different names, depending on their role and objective. PayPal X Open Payments Platform enables almost any of them.
The API Caller also needs a PayPal Business Account as the application is moving money between multiple parties and could possibly take it’s own cut/commission.
Before we talk more about the toolkit, classes and objects it provides, let’s first take a look at the APIs it supports.