All Projects → Enngage → Ngx Paypal

Enngage / Ngx Paypal

Licence: mit
Paypal integration for Angular

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Ngx Paypal

React Native Paypal
PayPal clone with React Native
Stars: ✭ 47 (-70.62%)
Mutual labels:  paypal
Django Shop Tutorial
Use Django To Create A Simple Shopping Site Tutorial
Stars: ✭ 109 (-31.87%)
Mutual labels:  paypal
Payum
PHP 7+ Payment processing library. It offers everything you need to work with payments: Credit card & offsite purchasing, subscriptions, payouts etc. - provided by Forma-Pro
Stars: ✭ 1,665 (+940.63%)
Mutual labels:  paypal
Dj Paypal
Paypal integration for Django - Inspired by Dj-Stripe
Stars: ✭ 55 (-65.62%)
Mutual labels:  paypal
Payumserver
Payment processing microservice. Written in Symfony4
Stars: ✭ 103 (-35.62%)
Mutual labels:  paypal
React Paypal Js
React components for the PayPal JS SDK
Stars: ✭ 111 (-30.62%)
Mutual labels:  paypal
Duranius Paypal Rest Api Php Library
If you need to integrate your website with PayPal REST API, then all you need is to download this library and you are ready to go. There are only two files you need to download and import to your project.
Stars: ✭ 13 (-91.87%)
Mutual labels:  paypal
Pay Java Parent
第三方支付对接全能支付Java开发工具包.优雅的轻量级支付模块集成支付对接支付整合(微信,支付宝,银联,友店,富友,跨境支付paypal,payoneer(P卡派安盈)易极付)app,扫码,网页刷脸付刷卡付条码付转账服务商模式,微信分账,微信合单支付、支持多种支付类型多支付账户,支付与业务完全剥离,简单几行代码即可实现支付,简单快速完成支付模块的开发,可轻松嵌入到任何系统里 目前仅是一个开发工具包(即SDK),只提供简单Web实现,建议使用maven或gradle引用本项目即可使用本SDK提供的各种支付相关的功能
Stars: ✭ 2,025 (+1165.63%)
Mutual labels:  paypal
Invoice As A Service
💰 Simple invoicing service (REST API): from JSON to PDF
Stars: ✭ 106 (-33.75%)
Mutual labels:  paypal
Payumlaravelpackage
Payum offers everything you need to work with payments. From simplest use cases to very advanced ones.
Stars: ✭ 121 (-24.37%)
Mutual labels:  paypal
React Native Paypal
React Native library that implements PayPal Checkout flow using purely native code
Stars: ✭ 70 (-56.25%)
Mutual labels:  paypal
Black.box
Plug-and-Play VPN router and unblocker
Stars: ✭ 89 (-44.37%)
Mutual labels:  paypal
Commerce.js
Open source, JS eCommerce SDK for building headless, Jamstack applications. Build custom storefronts, carts, and checkouts in any frontend framework, platform, or device. Integrates with Stripe, Square, PayPal, Paymill and Razorpay with support for 135+ currencies.
Stars: ✭ 112 (-30%)
Mutual labels:  paypal
Payment
支付宝支付、银联支付、微信支付、paypal、苹果内购支付
Stars: ✭ 48 (-70%)
Mutual labels:  paypal
Trado
Trado is a lightweight, easy to use ecommerce platform; designed to allow developers to quickly deploy a premium ecommerce store for their business
Stars: ✭ 149 (-6.87%)
Mutual labels:  paypal
Paypalexpresscheckoutnvp
[READ-ONLY] Subtree split of the Payum PaypalExpressCheckoutNvp Component -- clone into Payum/Paypal/ExpressCheckout/Nvp/ (master at payum/payum)
Stars: ✭ 35 (-78.12%)
Mutual labels:  paypal
Django Oscar Paypal
PayPal integration for django-oscar. Can be used without Oscar too.
Stars: ✭ 112 (-30%)
Mutual labels:  paypal
Shoppingcartexample
A simple shopping cart example iOS App
Stars: ✭ 160 (+0%)
Mutual labels:  paypal
Vue Paypal Checkout
A simple Vue.js wrapper component for paypal-checkout
Stars: ✭ 150 (-6.25%)
Mutual labels:  paypal
Donate In Git
Show how to add donate button in github
Stars: ✭ 118 (-26.25%)
Mutual labels:  paypal

npm version Build Status NPM

Angular PayPal

PayPal integration for Angular. For live example and documentation visit https://enngage.github.io/ngx-paypal/

This Angular library is based on PayPal's Javascript SDK. It does not support each and every feature of the JavaScript SDK so feel free to submit issues or PRs.

I strongly recommend checking out PayPal's docs linked above if you want to learn more about the flow of checkout process and meaning behind certain properties. There are ton of properties you can set within the createOrderOnClient method and good IDE will show you these properties so use that, I don't find it particulary useful to list all properties and their description here - PayPal docs is your friend.

Installation

npm install ngx-paypal --save

Import NgxPayPalModule in your module (i.e. AppModule)

Template

import { NgxPayPalModule } from 'ngx-paypal';
@NgModule({
  imports: [
    NgxPayPalModule,
    ...
  ],
})

Html code

<ngx-paypal [config]="payPalConfig"></ngx-paypal>

Creating orders on client

import {
    Component,
    OnInit
} from '@angular/core';
import {
    IPayPalConfig,
    ICreateOrderRequest 
} from 'ngx-paypal';

@Component({
    templateUrl: './your.component.html',
})
export class YourComponent implements OnInit {

    public payPalConfig ? : IPayPalConfig;

    ngOnInit(): void {
        this.initConfig();
    }

    private initConfig(): void {
        this.payPalConfig = {
            currency: 'EUR',
            clientId: 'sb',
            createOrderOnClient: (data) => < ICreateOrderRequest > {
                intent: 'CAPTURE',
                purchase_units: [{
                    amount: {
                        currency_code: 'EUR',
                        value: '9.99',
                        breakdown: {
                            item_total: {
                                currency_code: 'EUR',
                                value: '9.99'
                            }
                        }
                    },
                    items: [{
                        name: 'Enterprise Subscription',
                        quantity: '1',
                        category: 'DIGITAL_GOODS',
                        unit_amount: {
                            currency_code: 'EUR',
                            value: '9.99',
                        },
                    }]
                }]
            },
            advanced: {
                commit: 'true'
            },
            style: {
                label: 'paypal',
                layout: 'vertical'
            },
            onApprove: (data, actions) => {
                console.log('onApprove - transaction was approved, but not authorized', data, actions);
                actions.order.get().then(details => {
                    console.log('onApprove - you can get full order details inside onApprove: ', details);
                });

            },
            onClientAuthorization: (data) => {
                console.log('onClientAuthorization - you should probably inform your server about completed transaction at this point', data);
                this.showSuccess = true;
            },
            onCancel: (data, actions) => {
                console.log('OnCancel', data, actions);
                this.showCancel = true;

            },
            onError: err => {
                console.log('OnError', err);
                this.showError = true;
            },
            onClick: (data, actions) => {
                console.log('onClick', data, actions);
                this.resetStatus();
            }
        };
    }
}

Creating orders on server

import {
    Component,
    OnInit
} from '@angular/core';
import {
    IPayPalConfig,
    ICreateOrderRequest 
} from 'ngx-paypal';

@Component({
    templateUrl: './your.component.html',
})
export class YourComponent implements OnInit {

    public payPalConfig?: IPayPalConfig;

    ngOnInit(): void {
        this.initConfig();
    }

    private initConfig(): void {
        this.payPalConfig = {
            clientId: 'sb',
            // for creating orders (transactions) on server see
            // https://developer.paypal.com/docs/checkout/reference/server-integration/set-up-transaction/
            createOrderOnServer: (data) => fetch('/my-server/create-paypal-transaction')
                .then((res) => res.json())
                .then((order) => order.orderID),
            onApprove: (data, actions) => {
                console.log('onApprove - transaction was approved, but not authorized', data, actions);
                actions.order.get().then(details => {
                    console.log('onApprove - you can get full order details inside onApprove: ', details);
                });

            },
            onClientAuthorization: (data) => {
                console.log('onClientAuthorization - you should probably inform your server about completed transaction at this point', data);
                this.showSuccess = true;
            },
            onCancel: (data, actions) => {
                console.log('OnCancel', data, actions);
                this.showCancel = true;

            },
            onError: err => {
                console.log('OnError', err);
                this.showError = true;
            },
            onClick: (data, actions) => {
                console.log('onClick', data, actions);
                this.resetStatus();
            },
        };
    }
}

Authorizing on server

To authorize on payment on server, provide authorizeOnServer. If you do so, client validation is not used and therefore the onClientAuthorization will not be called.

import {
    Component,
    OnInit
} from '@angular/core';
import {
    IPayPalConfig,
    ICreateOrderRequest 
} from 'ngx-paypal';

@Component({
    templateUrl: './your.component.html',
})
export class YourComponent implements OnInit {

    public payPalConfig?: IPayPalConfig;

    ngOnInit(): void {
        this.initConfig();
    }

    private initConfig(): void {
        this.payPalConfig = {
            clientId: 'sb',
            // for creating orders (transactions) on server see
            // https://developer.paypal.com/docs/checkout/reference/server-integration/set-up-transaction/
            createOrderOnServer: (data) => fetch('/my-server/create-paypal-transaction')
                .then((res) => res.json())
                .then((order) => data.orderID),
            authorizeOnServer: (approveData) => {
                fetch('/my-server/authorize-paypal-transaction', {
                    body: JSON.stringify({
                    orderID: approveData.orderID
                    })
                }).then((res) => {
                    return res.json();
                }).then((details) => {
                    alert('Authorization created for ' + details.payer_given_name);
                });
            },
            onCancel: (data, actions) => {
                console.log('OnCancel', data, actions);
                this.showCancel = true;
            },
            onError: err => {
                console.log('OnError', err);
                this.showError = true;
            },
            onClick: (data, actions) => {
                console.log('onClick', data, actions);
                this.resetStatus();
            },
        };
    }
}

Multiple ngx-paypal components on the same page

If you want to have multiple PayPal buttons on the same page, you can do so only if they share some basic properties (e.g. currency, commit flag..) because these are configured via URL query parameters when requesting PayPal's javascript SDK. PayPal does not allow registesting multiple SDKs on the same page.

The key is to inject PayPalScriptService, register script manually and then call customInit with the PayPal API once your component is available. Note that if you use conditions (*ngIf) you will have to adjust the core accordingly because of the timings and call customInit once both PayPalApi has loaded and your component was initialized.

import {
    PayPalScriptService, IPayPalConfig
} from 'ngx-paypal';

export class YourComponent implements OnInit {

    public payPalConfig?: IPayPalConfig;

    @ViewChild('payPalElem1') paypalComponent1?:  NgxPaypalComponent;
    @ViewChild('payPalElem2') paypalComponent2?:  NgxPaypalComponent;

    constructor(
        private payPalScriptService: PayPalScriptService
    ) { }

    ngOnInit(): void {
        this.payPalConfig = {}; // your paypal config

        this.payPalScriptService.registerPayPalScript({
        clientId: 'sb',
        currency: 'EUR'
        }, (payPalApi) => {
            if (this.paypalComponent1) {
                this.paypalComponent1.customInit(payPalApi);
            }

            if (this.paypalComponent2) {
                this.paypalComponent2.customInit(payPalApi);
            }
        });
    }
}
  <ngx-paypal #payPalElem1 [config]="payPalConfig" [registerScript]="false"></ngx-paypal>
  <ngx-paypal #payPalElem2 [config]="payPalConfig" [registerScript]="false"></ngx-paypal>

Unit testing

Unit testing in Angular is possible, but a bit clunky because this component tries to dynamically include paypals's script if its not already loaded. You are not required to include in globally or manually which has a benefit of not loading until you actually use this component. This has a caveat though, since the load callback is executed outside of Angular's zone, performing unit tests might fail due to racing condition where Angular might fail the test before the script has a chance to load and initialize captcha.

A simple fix for this is wait certain amount of time so that everything has a chance to initialize. See example below:

beforeEach(() => {
        fixture = TestBed.createComponent(YourComponent);
        component = fixture.componentInstance;
        setTimeout(function () {
            fixture.detectChanges();
        }, 2000);
});

Breaking v5 release

Versions > 5 represent completely rewrite of the library and switch to latest PayPal JavaScript SDK. Its highly recommended to use this version. If you still wish to use previous version, check v4 branch for previous documentation.

Publishing lib

Under projects\ngx-paypal-lib run

npm run publish-lib

Publishing demo app

Under root, generate demo app with

npm run build-demo-gh-pages
npx ngh --dir=dist-demo
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].