GithubHelp home page GithubHelp logo

kim-nguyenkhn / paypal-example-components Goto Github PK

View Code? Open in Web Editor NEW

This project forked from paypal/paypal-example-components

0.0 1.0 0.0 46 KB

Example component module for a component for unified PayPal/Braintree web sdk

JavaScript 93.98% Shell 6.02%

paypal-example-components's Introduction

PayPal/Braintree Example Component

Example standalone component to be included in unified PayPal/Braintree client SDK

Quick start

See src/index.js

Tests

  • Run the tests:

    npm test

Testing with different/multiple browsers

npm run karma -- --browser=Chrome
npm run karma -- --browser=Safari
npm run karma -- --browser=Firefox
npm run karma -- --browser=Chrome,Safari,Firefox

Keeping the browser open after tests

npm run karma -- --browser=Chrome --keep-open

Releasing and Publishing

  • Publish your code with a patch version:
npm run release
  • Or npm run release:patch, npm run release:minor, npm run release:major

Module structure

  • /src - any code which should be transpiled, published, and end up in production
  • /test - karma tests for everything in /src
  • __sdk__.js - metadata for compiling and bundling the final component

/src/component.js

This module exports the public interface for the component.

export let LebowskiPay = {
    render(options) {
        ...
    }
};

Then the integrating site can run:

paypal.LebowskiPay.render({ ... });

/__sdk__.js

__sdk__.js defines any metadata which helps the sdk server compile and serve up the component.

export default {

    /**
     * Define the lebowski-pay component
     * Now developers can include paypal.com/sdk/js?components=lebowski-pay
     */

    'lebowski-pay': {

        /**
         * Entry point. Everything exported from this module will be exported
         * in the `window.paypal` namespace.
         */

        entry: './src/index',

        /**
         * Define a static namespace.
         * Server config will be available under the `__lebowski_pay__.serverConfig` global
         */

        staticNamespace: '__lebowski_pay__',

        /**
         * Define configuration required by this module
         * 
         * - This should be in the form of a graphql query.
         * - The query will be merged with queries defined by other modules
         * - The final config will be passed as `__lebowski_pay__.serverConfig` in `./src/index` 
         */

        configQuery: `
            fundingEligibility {
                card {
                    branded
                }
            }
        `
    }
};

FAQ

  • Why is there no webpack config, dist folder, or npm build command?

    This module (and modules like it) are not intended to be built as standalone components. It will be pulled in and compiled/bundled on the server-side, then combined with other modules.

  • When should I publish?

    When you publish, you're signing off on your changes being code-complete, fully tested, and ready for release. Publishing will not immediately trigger a deploy, but please only publish changes which are in a deployable state.

  • Can I define multiple components in one repo?

    Absolutely. __sdk__.js allows defining multiple entry points. These should generally represent different logical ui components, with separate concerns, and loose coupling. For example:

    modules: {
      'lebowski-pay': {
          entry: './src/components/lebowski-pay'
      },
      'walter-pay': {
          entry: './src/components/walter-pay'
      },
      'donnie-pay': {
          entry: './src/components/donnie-pay'
      }
    },

    Please bear in mind that this opens the door to any combination or permutation of these modules to be requested by the merchant -- hence the need for loose coupling. donnie-pay should never have a hard dependency on lebowski-pay being present.

  • Where is all of the karma, webpack, eslint, etc. config coming from?

    This module uses grumbler-scripts as a common source of configuration and defaults. Any of these can be overriden, either partially, or entirely, depending on the individual needs of the module. You'll notice .eslintrc.js, karma.conf.js, etc. are lightweight wrappers which only define module-specific overrides.

paypal-example-components's People

Contributors

quinnjn avatar braintreeps avatar

Watchers

James Cloos avatar

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.