This project is a Java Web Application that demonstrates the Express Checkout via Braintree SDK payment experience using the Braintree Client JavaScript SDKs and the server-side Java SDK.
Express Checkout via Braintree SDK allows you to integrate Express Checkout using the Braintree SDK without a Braintree account. There are two Payment Flows in the demonstration. Mouse-over the buttons in the Shopping Cart to review the Payment Flow diagrams.
-
Payment Flow 1: The Buyer selects Shipping Address and Wallet inside the PayPal mini-browser and completes the payment on the Seller's website.
-
Payment Flow 2: The Buyer provides Shipping Address on the Seller's website then completes the payment inside the PayPal mini-browser.
-
TLS v1.2 protocol. (Java 8+ supports TLS v1.2 protocol by default)
-
Apache Tomcat version is
7.0.57. For more information about Apache Tomcat, please visit their site. -
In
config.properties, set up the ACCESS_TOKEN for the merchant account that will be used and setENVIRONMENTto sandbox or production. This merchant account needs to be set up with currencies that will be accepted.
- Stop Apache Tomcat if running.
- Copy
ECBraintreeSDK.war(/ECBraintreeSDK/dist/ECBraintreeSDK.war) to Tomcat'swebappsfolder. - Restart Apache Tomcat
- Navigate to
http://localhost:port/ECBraintreeSDK. The default port for Tomcat is 8080.
The starting point is index.jsp. Click the PayPal Check out" button (Payment flow 1) or "Proceed to Checkout" button (Payment flow 2) to start a payment flow.
In the PayPal mini-browser, depending on the flow configuration, you'll see a Continue button (Payment flow 1) or a Pay Now button (Payment flow 2) . If the flow is cancelled, you'll be redirected to "cancel.jsp".
index.jsp (Payment Flow 1) and checkoutpage.jsp (Payment Flow 2) do the following:
-
When a page is loaded containing client-side code (i.e.
index.jspandcheckoutpage.jsp), an authorization token is returned by getToken() inBtTransactionHelper.java. -
When the payment is submitted, the request parameters are posted to [
BtCheckoutServlet.java] (ECBraintreeSDK/src/com/paypal/BtCheckoutServlet.java).
Review the forms and JavaScript in index.jsp (Payment flow 1) and checkoutpage.jsp (Payment flow 2) to better understand the configurations.
To begin your own development, either import ECBraintreeSDK.war into a new project, or import the ECBraintreeSDK folder.
- Open Eclipse EE
- Open your Workspace
- File > Import...
- Web > WAR file > Next
- WAR File:
a. Browse to
dist/ECBraintreeSDK.war - Web project: ECBraintreeSDK
- Target runtime: a. Select New... b. Select Apache Tomcat v7.0 c. Click Next d. Tomcat installation directory: i. Select Browse... ii. Navigate to the Tomcat installation directory and click OK e. JRE: Workbench Default JRE f. Click Finish
- Click Finish
- Right-mouse click on
ECBraintreeSDKin Project Explorer - Select Run As > Run on Server a. Server runtime environment: Apache Tomcat v7.0
- Select Finish
Refer to the project's folder structure below.
dist: contains the project's web archive (WAR) file.src: contains the server-side Java code.test: contains the test case files.build: place for compiled classes.doc: Javadoc code documentation from source codeWebContent: this is where the JSP pages, css, js and images are located.
Note: To import required jar files, make sure that /ECBraintreeSDK/WebContent/WEB-INF/lib/ is part of the build path.
Note: config.properties contains the Braintree JavScript Client SDK URLs and the PayPal Access Token.