14.2.7 • Published 2 years ago

@zenkipay-pkg/angular v14.2.7

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

Zenkipay for Angular 14


Installation

npm i @zenkipay-pkg/angular@14

Important: In our dependencies we use the version of rxjs that uses the version of Angular selected, if your version of rxjs is not the one that comes by default with your version of Angular it may give you some errors of compatibility, you can try between versions according to your version of rxjs.


Usage

Adds Zenkipay2Module to your Angular module.

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { Zenkipay2Module } from '@zenkipay-pkg/angular';

import { AppComponent } from './app.component';

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

After that, yo can use own zenkipay-button-2 component or own Zenkipay2Service provider:

zenkipay-button-2 component

You can use it inputs and it output.

The next table explains available inputs:

InputTypeDescription
dataZenkipayOptionsRequired, it must contains payment details.
styleStyle2Optional, it modifies the styles of the button.

The next table explains available outputs:

OutputTypeDescription
eventsZenkipayDataIt emits each update of the payment
errorErrorIt emits when there are an error

Zenkipay2Service provider

You can inject Zenkipay2Service provider in your components/providers.

declare class Zenkipay2Service {
  public openModal(options: ZenkipayOptions): Observable<ZenkipayData>;

  public closeModal(): Observable<boolean>;
}

Entity definitions

Styles

class Style2 {
  theme?: Theme2;
  size?: Size2;
  shape?: Shape2;
  expand?: Expand;
  type?: Type;
  colors?: Colors;
}

type Theme2 = 'default' | 'orange' | 'purple' | 'dark';

type Size2 = 'default' | 'sm';

type Shape2 = 'default' | 'pill';

type Expand = 'default' | 'block';

type Type = 'default' | 'cryptos';

class Colors {
  background?: string;
  border?: string;
  font?: string;
}

ZenkipayOptions

class ZenkipayOptions {
  orderId!: string;
  paymentSignature!: string;
}

ZenkipayData

class ZenkipayData {
  postMsgType!: POST_MSG_TYPE;
  isCompleted!: boolean; // It's `true` when modal is closed
  data!: ConfirmingMsg | DoneMsg | null;
}

enum POST_MSG_TYPE {
  CANCEL = 'cancel',
  DONE = 'done',
  CLOSE = 'close',
  ERROR = 'error',
  PROCESSING_PAYMENT = 'processing_payment',
  SHOPPER_PAYMENT_CONFIRMATION = 'shopper_payment_confirmation',
}

class ConfirmingMsg {
  transaction!: MsgTrxDetails;
}

class DoneMsg extends ConfirmingMsg {
  orderId!: string;
}

Example

app.component.html

<zenkipay-button-2
  [data]="data"
  [style]="style"
  (events)="events($event)"
  (error)="error($event)"
></zenkipay-button-2>

<button (click)="payWithZenkipay()">Pay with Zenkipay</button>

app.component.ts

import { Component, OnDestroy } from '@angular/core';
import {
  Style2,
  Zenkipay2Service,
  ZenkipayData,
  ZenkipayOptions,
} from '@zenkipay-pkg/angular';
import { catchError, filter, Observable, of, Subscription } from 'rxjs';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss'],
})
export class AppComponent implements OnDestroy {
  private readonly _subscriptions: Subscription[] = [];

  public style: Style2 = { shape: 'pill' };

  public data: ZenkipayOptions = {
    paymentSignature: 'SET_YOUR_PAYMENT_SIGNATURE_HERE',
    orderId: 'SET_YOUR_ORDER_ID_HERE',
  };

  constructor(private readonly _zenkipayService: Zenkipay2Service) {}

  public ngOnDestroy(): void {
    for (let i = 0; i < this._subscriptions.length; i++) {
      this._subscriptions[i].unsubscribe();
    }
  }

  public events(data: ZenkipayData): void {
    console.log(data);
  }

  public error(error: Error): void {
    console.error(error);
  }

  public payWithZenkipay(): void {
    this._subscriptions.push(
      this._zenkipayService
        .openModal(this.data)
        .pipe(
          catchError((error: Error): Observable<null> => {
            console.error(error);
            return of(null);
          }),
          filter(Boolean)
        )
        .subscribe((data: ZenkipayData): void => {
          console.log(data);
        })
    );
  }
}
14.2.7

2 years ago

13.2.7

2 years ago

12.2.7

2 years ago

11.2.7

2 years ago

10.2.7

2 years ago

9.2.7

2 years ago

8.2.7

2 years ago

7.2.7

2 years ago

6.2.7

2 years ago

14.2.6

3 years ago

13.2.6

3 years ago

12.2.6

3 years ago

11.2.6

3 years ago

10.2.6

3 years ago

9.2.6

3 years ago

8.2.6

3 years ago

7.2.6

3 years ago

6.2.6

3 years ago

14.2.5

3 years ago

13.2.5

3 years ago

12.2.5

3 years ago

11.2.5

3 years ago

10.2.5

3 years ago

9.2.5

3 years ago

8.2.5

3 years ago

7.2.5

3 years ago

6.2.5

3 years ago

14.2.4

3 years ago

13.2.4

3 years ago

12.2.4

3 years ago

11.2.4

3 years ago

10.2.4

3 years ago

9.2.4

3 years ago

8.2.4

3 years ago

7.2.4

3 years ago

6.2.4

3 years ago

14.2.3

3 years ago

13.2.3

3 years ago

12.2.3

3 years ago

11.2.3

3 years ago

10.2.3

3 years ago

9.2.3

3 years ago

8.2.3

3 years ago

7.2.3

3 years ago

6.2.3

3 years ago

14.2.2

3 years ago

13.2.2

3 years ago

12.2.2

3 years ago

11.2.2

3 years ago

10.2.2

3 years ago

9.2.2

3 years ago

8.2.2

3 years ago

7.2.2

3 years ago

6.2.2

3 years ago

14.2.1

3 years ago

13.2.1

3 years ago

12.2.1

3 years ago

11.2.1

3 years ago

10.2.1

3 years ago

9.2.1

3 years ago

8.2.1

3 years ago

7.2.1

3 years ago

6.2.1

3 years ago

14.2.0

3 years ago

13.2.0

3 years ago

12.2.0

3 years ago

11.2.0

3 years ago

10.2.0

3 years ago

9.2.0

3 years ago

8.2.0

3 years ago

7.2.0

3 years ago

6.2.0

3 years ago

14.1.0

3 years ago

12.1.0

3 years ago

11.1.0

3 years ago

10.1.0

3 years ago

9.1.0

3 years ago

8.1.0

3 years ago

7.1.0

3 years ago

6.1.0

3 years ago

13.1.0

3 years ago

14.0.0

3 years ago

13.0.1

3 years ago

12.0.0

3 years ago

11.0.0

3 years ago

10.0.0

3 years ago

9.0.0

3 years ago

8.0.0

3 years ago

7.0.0

3 years ago

6.0.0

3 years ago

7.0.2

3 years ago

6.0.2

3 years ago

6.0.1

3 years ago

13.0.0

3 years ago