Skip to content

Conversation

bdellis
Copy link
Contributor

@bdellis bdellis commented Jul 22, 2025

Add jsdocs to methods in the repo - this is a first stab to get feedback from the team.

/**
* Initializes the PayPal Web SDK, determines eligible payment methods,
* and sets up the appropriate payment buttons.
* @async
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be great to explain how this function gets invoked. What do you think of this?

/**
 * Initializes the PayPal Web SDK, determines eligible payment methods,
 * and sets up the appropriate payment buttons. This function is invoked
 * by the SDK script tag's "onload" event.
 *
 * ```html
 * <script
 *   async
 *   src="https://www.sandbox.paypal.com/web-sdk/v6/core"
 *   onload="onPayPalWebSdkLoaded()">
 * </script>
 * ```
 *
 * @async
 * @function
 * @returns {Promise<void>}
 */

}
}

/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was reading up on jsdoc and it looks like we can use typedef to type out and reuse this objects. Would be great to leverage to explain what's available in each object:

/**
 * @typedef {Object} OnApproveData
 * @property {string} orderId
 * @property {string} payerId
 */

/**
 * @typedef {Object} OnCancelData
 * @property {string|undefined} orderId
 */

/**
 * Options object for payment session event handlers.
 * @typedef {Object} PaymentSessionOptions
 * @property {function(OnApproveData): Promise<void>} onApprove - Called when the buyer approves the payment.
 * @property {function(OnCancelData): void} onCancel - Called when the buyer abandons the payment.
 * @property {function(Error): void} onError - Called when an unexpected error occurs.
 */

* @async
* @function
* @param {Object} sdkInstance - The PayPal SDK instance.
* @param {Object} paylaterPaymentMethodDetails - The Pay Later payment method details.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm learning that we can type out object properties like this too:

Suggested change
* @param {Object} paylaterPaymentMethodDetails - The Pay Later payment method details.
* @param {{ productCode: string, countryCode: string }} paylaterPaymentMethodDetails - The Pay Later payment method details.

@gregjopa
Copy link
Contributor

@bdellis this is an incredible start with leveraging code comments to better explain our examples. I left some comments with some ideas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants