Skip to content
Fang Shuo edited this page May 3, 2020 · 2 revisions

peoplepower-web interacts with paypal through the src/lib/payal/paypal.js file. The most important component there is the PayPalButton button component, which is actually a package ('react-paypal-button-v2') which we use to interact with paypal.

Main idea

PayPalButton requires a clientId, which is the clientId tied to a Paypal developer account. Right now, we are using sandbox credentials for this, which we got through signing up with Paypal. Note that sandbox credentials can only be used with https://www.sandbox.paypal.com/ as opposed to https://www.paypal.com/

The PayPalButton also takes in an onSuccess prop, which is what we can use to pass a function into the PaypalButton. This function will be invoked once Paypal successfully processes a payment.

The details and data arguments are passed into onSuccess (more on this in the details and data section below).

Currently, we use the onSuccess function to log details of transactions into Airtable.

Verifying payment

Currently, the way that we verify Paypal functionality is as follows:

  1. Ensure that the onSuccess function is invoked, which relies on the API contract that the function is only invoked on success
  2. Ensure that the payment is reflected on the Paypal dashboard at https://www.sandbox.paypal.com/
  3. Ensure that the payment is recorded in Airtable, with the appropriate information

details and data

The data object is as follows:

orderID: "SOME ORDER ID"
payerID: "SOME PAYER ID"

The details object is as follows:

create_time: "2019-11-12T04:44:42Z"
id: "SOME_ID_HERE"
intent: "SOME INTENT HERE"
links: [{
  href: "SOME HREF HERE"
  method: "HTTP METHOD"
  rel: "self"
  title: "SOME TITLE"
}]
payer: {
  email_address: "SOME EMAIL ADDRESS", 
  payer_id: "SOME PAYER ID", 
  address: {…}, 
  name: {…}
}
purchase_units: [{…(EXPANDED BELOW)}]
status: "SOME STATUS"
update_time: "2019-11-12T04:45:33Z"

Expand on the purchase_units field,

amount: 
  value: "SOME VALUE (IN DOLLARS)", 
  currency_code: "SOME CURRENCY CODE"
payee: 
  email_address: "SOME EMAIL ADDREESS", 
  merchant_id: "SOME MERCHANT ID"
payments: 
  captures: [{
      amount: {value: "SOME VALUE (IN DOLLARS)", currency_code: "SOME CURRENCY CODE"}
      create_time: "2019-11-12T04:58:14Z"
      final_capture: true/false
      id: "SOME ID"
      links: (3) [{…}, {…}, {…}]
      seller_protection: {status: "SOME STATUS", dispute_categories: Array(2)}
      status: "SOME STATUS"
      update_time: "2019-11-12T04:58:14Z"
  }]
    
  reference_id: "SOME REFERENCE ID"
shipping:
  address:
      address_line_1: "X X STREET"
      admin_area_1: "SOME STATE"
      admin_area_2: "SOME AREA"
      country_code: "SOME COUNTRY"
      postal_code: "POSTAL CODE HERE"
  name:
      full_name: "FULL NAME HERE"

status: "SOME STATUS HERE"
update_time: "2019-11-12T04:58:14Z"