PayPal Inbound Example

The following example is a PayPal inbound configuration.

{
  "$version": "2",
  "api": {
    "base_url": "https://api.paypal.com"
  },
  "auth": {
    "paypal-oauth": {
      "type": "oauth2",
      "configuration": {
        "authorization_base_url": "https://www.paypal.com/connect?flowEntry=static",
        "client_id": "[insert your client id here]",
        "client_secret": "[insert your secret here]",
        "scopes": [
          "profile", "email", "https://uri.paypal.com/services/paypalattributes"
        ],
        "token_request_body": "grant_type=authorization_code",
        "token_url": "https://api.paypal.com/v1/oauth2/token",
        "refresh_url": "https://api.paypal.com/v1/oauth2/token"
      }
    }
  },
  "data_intake": [
    {
      "name": "paypal_webhook",
      "type": "webhook",
      "scope": "application",
      "resource_id": {
        "!jq": ".event_type"
      },
      "account_id": {
        "!jq": ".resource.purchase_units[0].payee.email_address"
      },
      "create": {
        "!pipe": [
          {
            "!http": {
              "body": {
                "url": "${webhook.url}",
                "event_types": [
                  {
                    "name": "CHECKOUT.ORDER.APPROVED"
                  },
                  {
                    "name": "CHECKOUT.ORDER.COMPLETED"
                  }
                ]
              },
              "method": "POST",
              "path": "/v1/notifications/webhooks",
              "headers": {
                "content-type": "application/json"
              }
            }
          },
          {
            "!jq": ".body | {webhook_id: .id}"
          },
          {
            "!save": {
              "scope": "application"
            }
          }
        ]
      },
      "delete": {
        "!http": {
          "method": "DELETE",
          "path": "/v1/notifications/webhooks/${data.application.webhook_id}",
          "headers": {
            "content-type": "application/json"
          }
        }
      }
    }
  ],
  "workflows": [
    {
      "name": "create-contacts-from-paypal",
      "label": "Create Contacts From PayPal Orders",
      "description": "Create/update a ActiveCampaign contact when a customer approves or completes an order using PayPal.",
      "type": "generic",
      "resource_type": "events",
      "data_intake": "paypal_webhook",
      "auth": "paypal-oauth",
      "setup": {
        "connect": {
          "label": "Connect",
          "describe_connection": {
            "!pipe": [
              {
                "!http": {
                  "method": "GET",
                  "path": "/v1/identity/oauth2/userinfo?schema=paypalv1.1",
                  "headers": {
                    "content-type": "application/json"
                  }
                }
              },
              {
                "!jq": "(.body.emails[] | select(.primary == true) | .value) as $email | {account_id: $email, description: (.name + \" - \" + $email)}"
              }
            ]
          }
        },
        "select": {
          "label": "Select PayPal Event",
          "description": "Select a PayPal Event.",
          "describe_selection": {
            "resource_id": {
              "!jq": "[${custom_data.resource.value}, ${custom_data.event.value}] | join(\".\")"
            },
            "display": {
              "!jq": "[${custom_data.resource.display}, ${custom_data.event.display}] | join(\" \")"
            }
          },
          "form_fields": [
            {
              "label": "Choose Resource",
              "type": "dropdown",
              "id": "resource",
              "placeholder": "Select Resource",
              "options": {
                "!jq": "[{display: \"Checkout Order\", value: \"CHECKOUT.ORDER\"}]"
              }
            },
            {
              "label": "Choose Event Type",
              "type": "dropdown",
              "id": "event",
              "placeholder": "Select Event",
              "options": {
                "!jq": "[{display: \"Approved\", value: \"APPROVED\"}, {display: \"Completed\", value: \"COMPLETED\"}]"
              }
            }
          ]
        },
        "map": {
          "label": "Mapping",
          "describe_source": {
            "label": "PayPal",
            "options": {
              "!jq": "[\"create_time\", \"summary\", \"given_name\", \"surname\", \"email_address\", \"payer_id\", \"national_number\", \"birth_date\", \"tax_id\", \"tax_id_type\", \"address_line_1\", \"address_line_2\", \"admin_area_2\", \"admin_area_1\", \"postal_code\", \"country_code\"] | map({id: ., title: . | split(\"_\") | join(\" \")})"
            }
          },
          "describe_target": {
            "label": "ActiveCampaign",
            "options": {
              "!resource": "ActiveCampaignContact.fields"
            }
          }
        }
      },
      "data_pipeline": {
        "source": {
          "!jq": "{create_time: .create_time, summary: .summary} + (.resource.payer | (.name | {given_name: .given_name, surname: .surname }) + {email_address: .email_address, payer_id: .payer_id} +  (.phone.phone_number | {national_number: .national_number}) + {birth_date: .birth_date}  +  (.tax_info | {tax_id: .tax_id, tax_id_type: .tax_id_type }) + (.address | {address_line_1: .address_line_1, address_line_2: .address_line_2, admin_area_2: .admin_area_2, admin_area_1: .admin_area_1, postal_code: .postal_code, country_code: .country_code }))"
        },
        "target": {
          "!resource": "ActiveCampaignContact"
        }
      }
    }
  ]
}