npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@paycargo/js

v0.5.2

Published

Paycargo web components for micro frontends

Downloads

291

Readme

Overview

By implementing PayCargo Checkout, a seamless experience is afforded to its users who may work within the framework of their choice. In effect, users will not be redirected to different pages and may, instead, remain within the host portal.

There are two ways to install the PayCargo Checkout component:

  1. Load through script tag
  2. NPM packages

Setting up the Component Using JavaScript

Integrating a component can be done via script tag within the head of an HTML page, and then calling the component within the body.

<html>
   <head>
     <script
      type="module"
      src="https://jstest.paycargo.com/checkout.paycargo.com/paycargo-checkout/paycargo-checkout.esm.js">
     </script>
    </head>
   <body>
     <paycargo-checkout></paycargo-checkout>
   </body>
 </html>

How to Pass Data to the PayCargo Checkout Component

Properties

| Property Name | Values | Type | Required | Description | |---------------|--------------------------|----------------------------|--------------------|----------------------------------------------------------| | options | | object | :heavy_check_mark: | Passing necessary options into the component | | | env | string | :heavy_check_mark: | Options: local, dev, test, prod | | | code | string | :heavy_check_mark: | PayCargo integration code | | | originURL | string | :heavy_check_mark: | Host URL where component is loaded | | | brand | string | | | | | size | string | | Options: full, lg, md where the default size is md | | visible | true / false | boolean | :heavy_check_mark: | To make PayCargo Checkout component visible or hidden | | pcTransactions| | object[] | :heavy_check_mark: | PayCargo transaction object | | | type | string | :heavy_check_mark: | Transaction type (example: Invoice, Terminal Fee, etc)| | | vendorId | number / null | :heavy_check_mark: | | | | number | string | :heavy_check_mark: | | | | direction | 'Inbound' / 'Outbound' | :heavy_check_mark: | | | | total | number | :heavy_check_mark: | Amount of total transaction. If transaction lines are present, then the total should equal the sum of all transaction line amounts| | | arrivalDate | string / date | | | | | hasArrived | 'Y' / 'N' | :heavy_check_mark: | | | | bolLink | string | | | | | parent | string | | | | | shipperRefNumber | string | | | | | customerRefNumber | string | | | | | subcategory | string | | | | | paymentDueDate | date | | | | | notes | string / null | | | | | transactionLines | array | | |


Transaction Lines

| Property Name | Values | Type | Required | Description | |---------------|--------------------------|----------------------------|--------------------|----------------------------------------------------------| | transactionLines| | object | | Passing necessary options into the component. Note: these property names are case sensitive | | | AMOUNT | number | :heavy_check_mark: | Amount for transaction line | | | DESCRIPTION | string | :heavy_check_mark: | | | | START_DATE | string / date | | | | | END_DATE | string / date | | | | | QUANTITY | number | | | | | UNIT_PRICE | number | | | | | containerNumber | string | | OSRA: container number | | | availabilityDate | string / date | | OSRA: first available date | | | pod | string | | OSRA: port of discharge | | | sfd | string | | OSRA: start free day | | | lfd | string | | OSRA: last free day | | | freeTimeDays | string | | OSRA: free time days | | | ddr | string | | OSRA: demurrage detention rule | | | feeContact | string | | OSRA: mitigation contact | | | complianceStatement | string | | OSRA: compliance statement | | | commonCarrierStatement | string | | OSRA: common carrier statement |


Examples on Passing Values to PayCargo Checkout

In the element of the HTML file:

<paycargo-checkout options='{
    "env": "test",
    "code": "ecuww",
    "originURL": "http://localhost:3333/",
    "brand": "ecuww",
    "size": "full"
  }'
/>

photo 1

Please note the following:

  • We have indicated test here as the environment for your testing purposes.
  • Your URL must be provided to PayCargo's Development Team so it may be whitelisted.
  • You must request code and brand from PayCargo's Development Team as it must be supplied for your particular integration.
  • You may choose how to display the modal, i.e. how much space the modal will take up within your portal.
  • The Console will show 404 errors if the Options property is not being passed. photo 2

Example of How to Pass Data to the Transaction Object

  <script>

  const transactions = [
    {
      vendorId: 279602,
      type: 'AWB',
      number: 'abc98211',
      total: 150.0
    },
    {
      vendorId: 279602,
      type: 'Invoice',
      number: 'abc98212',
      total: 103.0
    },
    {
      vendorId: 280003,
      type: 'Terminal Fee',
      number: 'abc98213',
      total: 204.0
    }
  ]

  let selected = [] // sets the selected transactions
  const paycargoCheckout = document.querySelector('paycargo-checkout')
  const checkboxes = document.getElementsByName('trans-box')
  checkboxes.forEach((el) => {
    el.addEventListener('click', event => {
      const {target} = event
      const {name, value, checked} = target
      if (checked) {
        selected.push(transactions[value])
        paycargoCheckout.setAttribute('pc-transactions', JSON.stringify(selected))
      } else {
        selected = selected.filter(trans => trans.index != value)
        paycargoCheckout.setAttribute('pc-transactions', JSON.stringify(selected))
      }
    })
  })

  </script>

If you successfully passed transaction object(s) to the pc-transactions property and clicked the "PayCargo Checkout" button, then it should display as such: photo 4 5

Event Listeners

There are two different event listeners that may be implemented: (1) when a user approves a transaction and (2) when a user closes the modal for any reason. We strongly advise listening to both of these events so action may be taken in accordance with the response given. As such, the possibilities of misalignment or discrepancies are minimized.

To access these events, select the component through the HTML querySelector and add an event listener for the 'close' event:

  const paycargoCheckout = document.querySelector('paycargo-checkout')

  paycargoCheckout.addEventListener('close', event => {
    console.log({event})
    console.log('Closed, event.details', event.detail)
    console.log('Closed, event.details.data', event.detail.data)
  })

When a user closes the PayCargo Checkout modal without taking any action, the event should return the following object detail:

data: null
result: {msg: 'Closed by user.', code: 204}

When a user has successfully made a payment, a similar event is emitted. The eventName is paymentResponse:

  const paycargoCheckout = document.querySelector('paycargo-checkout')

  paycargoCheckout.addEventListener('paymentResponse', event => {
    console.log('PayCargo Payment Response Event', event.detail)
  })

The event.detail structure for a successful payment is as follows: photo 5

The properties that may be of most use are:

  • data.error
    • create - any transaction that encountered an error during creation
    • approve - any transaction that encountered an error when approving
  • data.success
    • create - this contains all transactions that have been successfully created
    • approve - this contains all transactions that have been successfully approved

This is an example of a JSON object of the response:

{
    "result": {
        "msg": "Successfully created and approved batch transactions",
        "code": 200
    },
    "data": {
        "success": {
            "approve": [
                {
                    "transactionId": 591842,
                    "vendorId": 281283,
                    "payerId": 283270,
                    "userEmail": "[email protected]",
                    "totalAmount": 22880,
                    "approvalDate": "2023-10-02T18:02:53-04:00",
                    "approvalDateUTC": "2023-10-02T22:02:53Z",
                    "number": "SEGU2028243",
                    "type": "Demurrage",
                    "transactionFee": 12.5,
                    "financeFee": 0,
                    "processingFee": 0,
                    "annualFee": 0,
                    "currency": "USD",
                    "payerName": "The Capone Mafia",
                    "vendorName": "YUSEN TERMINAL INC (LA) BERTH 214",
                    "payerRefNumber": null,
                    "customerRefNumber": "6018998010",
                    "parent": "unique id from post",
                    "subcategory": "STORAGE CHARGES",
                    "shipperRefNumber": "89",
                    "bolLink": "HAB",
                    "notes": "pc-checkout",
                    "arrivalDate": null,
                    "departureDate": null,
                    "payerInternalNumber": "",
                    "payerFileNumber": "",
                    "payerVoucherNumber": "",
                    "payerInvoiceNumber": "",
                    "msg": "Transaction paid",
                    "result": {
                        "msg": "Transaction paid",
                        "code": "200"
                    }
                }
            ],
            "create": [
                {
                    "result": {
                        "msg": "Transaction created",
                        "code": 201
                    },
                    "data": {
                        "transactionId": 591842,
                        "vendorId": 281283,
                        "payerId": 283270,
                        "userEmail": "[email protected]",
                        "totalAmount": 22880,
                        "approvalDate": null,
                        "approvalDateUTC": null,
                        "number": "SEGU2028243",
                        "type": "Demurrage",
                        "currency": "USD",
                        "payerName": "The Capone Mafia",
                        "payerRefNumber": null,
                        "customerRefNumber": "6018998010",
                        "parent": "unique id from post",
                        "subcategory": "STORAGE CHARGES",
                        "shipperRefNumber": "89",
                        "bolLink": "HAB",
                        "notes": "pc-checkout",
                        "arrivalDate": null,
                        "departureDate": null,
                        "payerInternalNumber": "",
                        "payerFileNumber": "",
                        "payerVoucherNumber": "",
                        "payerInvoiceNumber": "",
                        "transactionLines": {
                            "error": [],
                            "success": [
                                {
                                    "msg": "Successfully created transaction line",
                                    "transactionLineId": 78262
                                }
                            ]
                        }
                    }
                }
            ]
        },
        "error": {
            "approve": [],
            "create": []
        },
        "transactions": [
            {
                "transactionId": 591842,
                "vendorId": 281283,
                "payerId": 283270,
                "userEmail": "[email protected]",
                "totalAmount": 22880,
                "approvalDate": "2023-10-02T18:02:53-04:00",
                "approvalDateUTC": "2023-10-02T22:02:53Z",
                "number": "SEGU2028243",
                "type": "Demurrage",
                "transactionFee": 12.5,
                "financeFee": 0,
                "processingFee": 0,
                "annualFee": 0,
                "currency": "USD",
                "payerName": "The Capone Mafia",
                "vendorName": "YUSEN TERMINAL INC (LA) BERTH 214",
                "payerRefNumber": null,
                "customerRefNumber": "6018998010",
                "parent": "unique id from post",
                "subcategory": "STORAGE CHARGES",
                "shipperRefNumber": "89",
                "bolLink": "HAB",
                "notes": "pc-checkout",
                "arrivalDate": null,
                "departureDate": null,
                "payerInternalNumber": "",
                "payerFileNumber": "",
                "payerVoucherNumber": "",
                "payerInvoiceNumber": "",
                "msg": "Transaction paid",
                "result": {
                    "msg": "Transaction paid",
                    "code": "200"
                }
            }
        ],
        "fundsAvailable": [ ],
        "batchHeader": {
            "dateCreated": "2023-10-02T22:02:50.605Z",
            "currency": "USD",
            "payerId": 283270,
            "asOf": "2023-10-02T22:02:50.605Z",
            "batchId": 285415
        }
    }
}