Socket
Book a DemoInstallSign in
Socket

ng-payment-request-api

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ng-payment-request-api

Payment Request Api wrapper for angular 4/5

1.1.0
latest
Source
npmnpm
Version published
Weekly downloads
1
-85.71%
Maintainers
1
Weekly downloads
 
Created
Source

Angular Payment Request Api

Payment Request wrapper with TypeScript for angular +4.

Installation

To install this library, run:

$ npm install ng-payment-request-api --save

How to use

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
//Import payment request api module
import {PaymentRequestModule} from "ng-payment-request-api";


@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    PaymentRequestModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Parent Component

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'app';
  paymentOptions = {
    supportedPaymentMethods: [
      // regular payment
      {
        supportedMethods: 'basic-card',
      },
      //apply pay support. currently on safari ios only apply pay supported.
      {
        supportedMethods: 'https://apple.com/apple-pay',
        data: {
          version: 2,
          supportedNetworks:  ['amex', 'jcb', 'visa'],
          countryCode: 'US',
          merchantIdentifier: 'merchant.sleek.com',
          merchantCapabilities: ['supportsDebit', 'supportsCredit', 'supports3DS']
        }
      }
    ]
  };
  items: PaymentItem[] = [
    {
      label: 'product 1',
      amount: {
        value: 5,
        currency: "USD"
      }
    },
    {
      label: 'product 2',
      amount: {
        value: 8,
        currency: "USD"
      }
    }
    ];
  shippingOptions = [{
    id: 'economy',
    label: 'Economy Shipping (5-7 Days)',
    amount: {
      currency: 'USD',
      value: '0',
    },
  }, {
    id: 'express',
    label: 'Express Shipping (2-3 Days)',
    amount: {
      currency: 'USD',
      value: '5',
    },
  }, {
    id: 'next-day',
    label: 'Next Day Delivery',
    amount: {
      currency: 'USD',
      value: '12',
    },
  }];
  constructor() {}

  chargeClient(paymentResponse) {
    //TODO actual charge.
  }

  updateShippingOption(response) {
    // example:
    // response =  {
    //     total: 55,
    //     shippingOption :  {
    //       id: 'next-day',
    //       label: 'Next Day Delivery',
    //       amount: {
    //       currency: 'USD',
    //           value: '12',
    //       }
    //     }
    //  }
    }
}

And just use the Directive in your HTML

 <button appPaymentRequest
          [shippingOptions]="shippingOptions"
          [options]="paymentOptions"
          [items]="items"
          (onCheckout)="chargeClient($event)"
          (onShippingOptionChange)="updateShippingOption($event)">
      Checkout
  </button>

paymentOptions configuration can be found here. If you don't provide any parameters, default one are used.

License

MIT © Hai levi from Sleek Development

Keywords

angular2

FAQs

Package last updated on 04 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.