PayPal Checkout REST API Demo

Digital SLR Camera



Sample Sandbox Buyer Credentials:

Buyer EmailPassword
emily_doe@buyer.comqwer1234
bill_bong@buyer.comqwer1234
jack_potter@buyer.com123456789
harry_doe@buyer.com123456789
ron_brown@buyer.comqwer1234
bella_brown@buyer.comqwer1234

Pricing Details

Camera
Tax
Insurance
Handling Fee
Estimated Shipping
Shipping Discount
Total Amount
Currency


OR

README:

BEFORE YOU GET STARTED:
This code sample shows the new checkout flow called In-Context checkout experience. You need to meet the eligibility criteria to determine whether your integration will be a good candidate for In-Context checkout experience option. Please refer to the eligibility criteria .
If you are eligible for In-Context checkout based on the eligibility requirements, please refer to the 'In-Context Checkout integration steps' below. But, if you are not eligible, please refer to the 'Express Checkout integration steps' below.
PRE-READ:

1) Click on ‘Checkout with PayPal’ button and see the experience.
2) If you get any Firewall warning, add rule to the Firewall to allow incoming connections for your application.
3) Checkout with PayPal using a buyer sandbox account provided on this page. And you're done!
4) The sample code uses default sandbox REST App credentials which are set in paypalConfig.php. You can get your own REST app credentials by creating a REST app with the steps outlined here.
5) Make following changes in paypal_config.php:
- If using your own Sandbox seller account, update MERCHANT_ID with your merchant id. To get your merchant id, log into your Sandbox or Live business account as per the integration. The merchant ID can be found under My Account > Profile > My business info > Merchant account ID.
- Also, update SANDBOX_CLIENT_ID and SANDBOX_CLIENT_SECRET values with your REST app seller sandbox credentials
- SANDBOX_FLAG: Kept true for working with Sandbox, it will be false for live.

In-Context Checkout integration steps:

1) Copy the files and folders under 'Checkout' package to the same location where you have your shopping cart page.
2) Include apiCallsData.php at the top of the shopping cart page.
3) Copy the below <form> .. </form> to your shopping cart page.

<form id="myContainer" action="startPayment.php" method="POST">
    <input type="hidden" name="csrf" value="<?php echo($_SESSION['csrf']);?>"/>
    Camera:<input type="text" name="camera_amount" value="300" readonly></input><br>
    Tax:<input type="text" name="tax" value="5" readonly></input><br>
    Insurance:<input type="text" name="insurance" value="10" readonly></input><br>
    Handling:<input type="text" name="handling_fee" value="5" readonly></input><br>
    Est. Shipping:<input type="text" name="estimated_shipping" value="2" readonly></input><br>
    Shipping Discount:<input type="text" name="shipping_discount" value="-2" readonly></input><br>
    Total:<input type="text" name="total_amount" value="320" readonly></input><br>
    Currency:<input type="text" name="currencyCodeType" value="USD" readonly></input><br>
</form>

4) Include the following script on your shopping cart page:

<script type="text/javascript">
   window.paypalCheckoutReady = function () {
       paypal.checkout.setup('Your merchant id', {
           container: 'myContainer', //{String|HTMLElement|Array} where you want the PayPal button to reside
           environment: 'sandbox' //or 'production' depending on your environment
       });
   };
</script>
<script src="//www.paypalobjects.com/api/checkout.js" async></script>

5) Open your browser and navigate to your Shopping cart page. Click on 'Checkout with PayPal' button and complete the flow.
6) Read overview of REST API here and find the API reference here.



Express Checkout integration steps:

1) Copy the files and folders under 'Checkout' package to the same location where you have your shopping cart page.
2) Include apiCallsData.php at the top of the shopping cart page.
3) Copy the below <form> .. </form> to your shopping cart page.

<form action="startPayment.php" method="POST">
   <input type="hidden" name="csrf" value="<?php echo($_SESSION['csrf']);?>"/>
   Camera:<input type="text" name="camera_amount" value="300" readonly></input><br>
   Tax:<input type="text" name="tax" value="5" readonly></input><br>
   Insurance:<input type="text" name="insurance" value="10" readonly></input><br>
   Handling:<input type="text" name="handling_fee" value="5" readonly></input><br>
   Est. Shipping:<input type="text" name="estimated_shipping" value="2" readonly></input><br>
   Shipping Discount:<input type="text" name="shipping_discount" value="-2" readonly></input><br>
   Total:<input type="text" name="total_amount" value="320" readonly></input><br>
   Currency:<input type="text" name="currencyCodeType" value="USD" readonly></input><br>
   <input type="image" src="https://www.paypalobjects.com/webstatic/en_US/i/buttons/checkout-logo-large.png" alt="Check out with PayPal"></input>
</form>

4) Open your browser and navigate to your Shopping cart page. Click on 'Checkout with PayPal' button and complete the flow.
5) Read overview of REST API here and find the API reference here.