Comments (4)
I think the types don't really make sense?
export interface PayPalNamespace {
Buttons?: (
options?: PayPalButtonsComponentOptions,
) => PayPalButtonsComponent;
Marks?: (options?: PayPalMarksComponentOptions) => PayPalMarksComponent;
Messages?: (
options?: PayPalMessagesComponentOptions,
) => PayPalMessagesComponent;
HostedFields?: PayPalHostedFieldsComponent;
getFundingSources?: getFundingSources;
isFundingEligible?: isFundingEligible;
rememberFunding?: rememberFunding;
FUNDING?: Record<string, FUNDING_SOURCE>;
version: string;
}
Why is Buttons optional?
This makes the error go away but this shouldn't be necessary I would think? Or if it is, then the README should be updated at the very least?
if (paypal && paypal.Buttons) {
try {
await paypal.Buttons().render("#your-container-element");
} catch (error) {
console.error("failed to render the PayPal Buttons", error);
}
}
Another way to get rid of the error:
if (paypal) {
try {
await paypal.Buttons?.().render("#your-container-element");
} catch (error) {
console.error("failed to render the PayPal Buttons", error);
}
}
Notice the added ?.
before the function call.
from paypal-js.
@kevinrenskers Technically any component on the global paypal
object is optional. In your loadScript
you aren't passing components
which means by default we are including the buttons
component.
If you were using CardFields
or Messages
though, those components wouldn't exist on paypal
since the components weren't loaded.
Or if you had components: ['card-fields']
, then Buttons
wouldn't exist on paypal
since the buttons
component wasn't loaded.
We'll discuss this internally though, it may make sense to make all components on the paypal
object required and rely on runtime errors/messaging to tell the developer that the component does not exist on the paypal
object.
from paypal-js.
I think it's fine it's optional, but then the example code should deal with this?
from paypal-js.
Possibly, we will take a look. I'm wondering if there's a way to keep these optional but also not make every developer using TypeScript have to null check for each component. I guess it is technically safer, if for some reason a component didn't load, it would keep the PayPal JS SDK from taking down the rest of your web page.
We appreciate you bringing this up though!
from paypal-js.
Related Issues (20)
- Buttons not showing on Nuxt.js with ssr enabled HOT 2
- [Feature] array of strings should be allowed for `enable-funding` and `disable-funding` HOT 1
- [Bug] Button Installment Period not working HOT 2
- Payment Method HOT 18
- [Bug] Styling, button (pill) corners become square on hover [Firefox] HOT 2
- The window.paypal global variable is not available. HOT 2
- PayPalApplePayError: accountlifecycleserv responded with no legal_country_code field HOT 3
- How to inject crossorigin="anonymous" in script tag when using loadScript HOT 3
- [Bug] CreateOrderRequestBody seems incorrectly typed HOT 2
- [Bug] Paypal Subscription Error : Billing Plan Override is not allowed due to insufficient permissions HOT 3
- [Bug] Border of PayPal button invisible on some resolutions HOT 2
- [Bug] Infinite loading screen on safari when setting up a subscription HOT 2
- [Bug] Button background changes to blue when pending transaction HOT 2
- [Bug] the paypal Frame flicker when use onClick to validate form HOT 7
- Type mismatch in lastest version of @paypal/paypal-js and @paypal/react-paypal-js HOT 1
- [Feature] CardFields types HOT 2
- [Feature] Feature request
- Paypal JS SDK not loading for some users HOT 1
- https://join.robinhood.com
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from paypal-js.