Giter VIP home page Giter VIP logo

gatsby-plugin-paypal's Introduction

npm package npm downloads

Gatsby-Paypal-Plugin

gatsby-plugin-paypal

Add a PayPal Smart Payment Buttons to your Gatsby website easily.

Install

npm install --save gatsby-plugin-paypal

How to use Paypal plugin

// In your gatsby-config.js
module.exports = {
  plugins: [
    {
      resolve: `gatsby-plugin-paypal`,
      options: {
        clientId: `YOUR_CLIENT_ID`,
        currency: `EUR`, // Optional
        vault: true // Optional
      }
    }
  ]
};

Options

clientId

Your PayPal Client ID. You will find it on: https://developer.paypal.com/developer/applications/

currency

The currency of the transaction.

vault

The vault status of the transaction. If set to true:

  • Shows only funding sources that you can add to the vault
  • Set up a billing agreement, reference transaction, or subscription.

How to Use Paypal component

This is what a component using gatsby-plugin-paypal might look like:

import React from "react"
import Paypal from "gatsby-plugin-paypal"

const PaypalButton = () => (
    <Paypal 
      style={{
        shape: 'rect',
        color: 'blue',
        layout: 'horizontal',
        label: 'paypal',
      }}
      amount={10.1}
      currency="EUR"
    />
)

export default PaypalButton

Additional props of Paypal component

Name Type Description Default
amount string The amount value of the transaction.
currency string The currency of the transaction. The three-character ISO-4217 currency code. PayPal does not support all currencies. Warning: Uses the same value as declared in the plugin options USD
createOrder (data, actions) => any See createOrder
onApprove (data, actions) => any See onApprove
onError (error) => any See onError
onCancel (data) => any See onCancel
onInit (data, actions) => any See onInit
onClick () => any See onClick
shippingPreference string The shipping preferences. The possible values are: -NO_SHIPPING: Redact shipping address fields from the PayPal pages. Recommended for digital goods. - GET_FROM_FILE : Use the buyer-selected shipping address. - SET_PROVIDED_ADDRESS : Use the merchant-provided address. Buyer cannot change the address on the PayPal pages. If the merchant does not pass an address, the buyer can choose the address on PayPal pages. GET_FROM_FILE
createSubscription (data, actions) => any See createSubscription
style object See Customize the PayPal Buttons {}

Contribution

Pull requests

gatsby-plugin-paypal's People

Contributors

alexislepresle avatar buddhikajay avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

gatsby-plugin-paypal's Issues

Unable to override "createOrder" function with "createSubscription"

...props,

Right now shows an error when I am trying to use createSubscription because we can use it together with createOrder. I think should be like that:

window.paypal
        .Buttons({
          createOrder: (props.createOrder ? props.createOrder : createOrderPaypal),
          onApprove: (props.onApprove ? props.onApprove : onApprovePaypal),
          onError: (props.onError ? props.onError : onErrorPaypal),
          ...props,
        })
        .render('#paypal-button');

Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This

ร—
i have this error when i try to use this plugin

Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:

  1. You might have mismatching versions of React and the renderer (such as React DOM)
  2. You might be breaking the Rules of Hooks
  3. You might have more than one copy of React in the same app
    See https://fb.me/react-invalid-hook-call for tips about how to debug and fix this problem.

//component
`
import React from "react"
import Paypal from "gatsby-plugin-paypal"

const PaylpalButton = () => (
<Paypal
style={{
shape: 'rect',
color: 'blue',
layout: 'horizontal',
label: 'paypal',
}}
amount={10.1}
/>
)

export default PaylpalButton
`

//just a simple page
`
import React from 'react'
import PaypalButton from '../components/PaypalButton'

const Home= () => {
return (

)
}

export default Home
`

//config
.... plugins: [ { resolve:gatsby-plugin-paypal, options: { clientId: process.env.PAYPAL_ID } }, .... ] ....

plugin version 1.1

Vault parameter is missing

Hello!
I see that the plugin doesn't use the vault query parameter when loading the Paypal SDK script. However, in the docs it's said that this parameter must be true in case of subscription (its default value is false). Have you tested the plugin with subscriptions? Thanks!

Cannot read buttons of undefined

After installing the package and navigating to the button in the web browser it fails to load with the error in the title and points to the installed directory within node_modules

      window.paypal
        .Buttons({ 

Is what seems the be undefined at ./node_modules/gatsby-plugin-paypal/index.js:40

Update gatsby peer dependency

The project refers to "gatsby": "^2.32.13", as a peer dependency which is kinda old and the plugin seems to work fine with v3 too.

Pass value to amount

How can I pass a dynamic price to the button?

I have a form in my component that updates the quantity of ordered product and and useEffect hook that updates the orderTotal anytime the quantity changes. The updated orderTotal is not updated in the paypal button... My issue is probably not directly related to this plugin but rather to my general understanding of React and Gatsby...

const Cart = ({ isCartOpen, close }) => {
  const price = 29995;
  const [orderTotal, setOrderTotal] = useState(price);
  const [orderQuantity, setOrderQuantity] = useState(1);
  const data = useStaticQuery(graphql`
  {
      file(relativePath: {eq: "assets/images/laser-smart-projector-pico_3.webp"}) {
        childImageSharp {
          gatsbyImageData(aspectRatio: 1, placeholder: BLURRED)
        }
      }
    }
  `);
  const productPic = getImage(data.file);

  useEffect(() => {
    setOrderTotal(orderQuantity * price);
  }, [orderQuantity]);

  return (
    <StyledDiv isCartOpen={isCartOpen}>
      <button onClick={close}>
        <div className='closing'></div>
        <div className='closing'></div>
      </button>
      <div className='cart-content'>
        <Link to='/about' onClick={close}>
          <GatsbyImage image={productPic} alt='folded vze projector'/>
          VZE: Music Visualizer
        </Link>
        <form>
          <label htmlFor='quantity'>Ordered quantity:</label>
          <input
            type='number'
            name='quantity'
            id='quantity'
            value={orderQuantity}
            onChange={
              (e) => {
                setOrderQuantity(e.target.value);
              }}
            min={0}
            max={5}
            required/>
        </form>
        <p>your order total is {formatMoney(orderTotal)}</p>
      </div>
      <Paypal
        style={{
          shape: 'rect',
          color: 'blue',
          layout: 'horizontal',
          label: 'paypal',
        }}
        amount={orderTotal}
        currency='USD'
      />
    </StyledDiv>
  );
};

export default Cart;

Invalid hook call

I tried to integrate this plugin but I got this error. Followed instructions from gatsby official documentation. Any suggestion what this can be? I also get error Cannot read property 'Buttons' of undefined. (Sorry, my client ID was not good! It is working! )

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.