projects/angular-client-sdk/src/lib/components/pay-with-card.component.ts
| providers |
PaperEventsHandlerService
|
| selector | paper-pay-with-card |
Properties |
|
Methods |
Inputs |
Outputs |
Accessors |
constructor(renderer: Renderer2, element: ElementRef, eventsHandler: PaperEventsHandlerService)
|
||||||||||||
|
Parameters :
|
| chainName | |
Type : string
|
|
|
Current network name |
|
| checkoutId | |
Type : string
|
|
|
Checkout ID from Paper |
|
| config | |
Type : PaperPayWithCardInputs
|
|
|
Shorthand concatenation of all inputs |
|
| emailAddress | |
Type : string
|
|
|
Receiving email address |
|
| metadata | |
Type : Record<string, >
|
|
|
Metadata |
|
| options | |
Type : PaperSDKPayWithCardStyleOptions
|
|
|
Checkout style configurations |
|
| quantity | |
Type : number
|
|
|
Amount to purchase |
|
| recipientWalletAddress | |
Type : string
|
|
|
Receiving wallet address |
|
| cancel | |
|
Emit notification if transaction cancelled |
|
| error | |
|
Emit notification on un-successful checkout |
|
| paymentSuccess | |
|
Emit notification on successful payment |
|
| review | |
|
Emit notification when at review step |
|
| transferSuccess | |
|
Emit notification on successful transfer of assets |
|
| ngOnInit |
ngOnInit()
|
|
Returns :
void
|
| Private _config |
Type : PaperPayWithCardInputs
|
|
Overall configuration data store |
| Private payWithCardIFrame |
Type : HTMLIFrameElement
|
|
CC iFrame |
| config | ||||||
setconfig(config: PaperPayWithCardInputs)
|
||||||
|
Shorthand concatenation of all inputs
Parameters :
Returns :
void
|
| checkoutId | ||||||
setcheckoutId(checkoutId: string)
|
||||||
|
Checkout ID from Paper
Parameters :
Returns :
void
|
| recipientWalletAddress | ||||||
setrecipientWalletAddress(recipientWalletAddress: string)
|
||||||
|
Receiving wallet address
Parameters :
Returns :
void
|
| emailAddress | ||||||
setemailAddress(emailAddress: string)
|
||||||
|
Receiving email address
Parameters :
Returns :
void
|
| quantity | ||||||
setquantity(quantity: number)
|
||||||
|
Amount to purchase
Parameters :
Returns :
void
|
| metadata | ||||||
setmetadata(metadata: Record
|
||||||
|
Metadata
Parameters :
Returns :
void
|
| options | ||||||
setoptions(options: PaperSDKPayWithCardStyleOptions)
|
||||||
|
Checkout style configurations
Parameters :
Returns :
void
|
| chainName | ||||||
setchainName(chainName: string)
|
||||||
|
Current network name
Parameters :
Returns :
void
|
| requestURL |
getrequestURL()
|
|
src for iFrame
Returns :
string
|
import { HttpParams } from '@angular/common/http';
import { Component, ElementRef, Input, OnInit, Output, Renderer2 } from '@angular/core';
import { PAPER_APP_URL } from '../constants/paper-app-url';
import { PaperPayWithCardInputs } from '../interfaces/pay-with-card-inputs.interface';
import { PaperSDKPayWithCardStyleOptions } from '../interfaces/style-options.interface';
import { PaperEventsHandlerService } from '../services/events-handler.service';
@Component({
standalone: true,
selector: 'paper-pay-with-card',
imports: [],
providers: [PaperEventsHandlerService],
template: ``,
})
export class PaperPayWithCardComponent implements OnInit {
/** Shorthand concatenation of all inputs */
@Input() set config(config: PaperPayWithCardInputs) {
this._config = { ...config, options: { ...config.options } };
}
/** Checkout ID from Paper */
@Input() set checkoutId(checkoutId: string) {
this._config = { ...this._config, checkoutId };
}
/** Receiving wallet address */
@Input() set recipientWalletAddress(recipientWalletAddress: string) {
this._config = { ...this._config, recipientWalletAddress };
}
/** Receiving email address */
@Input() set emailAddress(emailAddress: string) {
this._config = { ...this._config, emailAddress };
}
/** Amount to purchase */
@Input() set quantity(quantity: number) {
this._config = { ...this._config, quantity: quantity };
}
/** Metadata */
@Input() set metadata(metadata: Record<string, unknown>) {
this._config = { ...this._config, metadata };
}
/** Checkout style configurations */
@Input() set options(options: PaperSDKPayWithCardStyleOptions) {
this._config = { ...this._config, options };
}
/** Current network name */
@Input() set chainName(chainName: string) {
this._config = { ...this._config, chainName };
}
/** Emit notification on successful payment */
@Output() paymentSuccess = this.eventsHandler.checkoutPaymentSuccess;
/** Emit notification on successful transfer of assets */
@Output() transferSuccess = this.eventsHandler.checkoutTransferSuccess;
/** Emit notification when at review step */
@Output() review = this.eventsHandler.checkoutReview;
/** Emit notification if transaction cancelled */
@Output() cancel = this.eventsHandler.checkoutCancel;
/** Emit notification on un-successful checkout */
@Output() error = this.eventsHandler.checkoutError;
/** Overall configuration data store */
private _config!: PaperPayWithCardInputs;
/** CC iFrame */
private payWithCardIFrame!: HTMLIFrameElement;
/** src for iFrame */
private get requestURL(): string {
const validKeysOnly = Object.entries(this._config ?? {}).reduce(
(acc, [k, v]) => (v ? { ...acc, [k]: v } : { ...acc }),
{}
);
const params = new HttpParams({
fromObject: validKeysOnly,
});
return `${PAPER_APP_URL}/sdk/v1/pay-with-card?${params.toString()}`;
}
constructor(
private renderer: Renderer2,
private element: ElementRef,
private eventsHandler: PaperEventsHandlerService
) {}
ngOnInit(): void {
this.payWithCardIFrame = this.renderer.createElement('iframe');
this.renderer.setAttribute(this.payWithCardIFrame, 'src', this.requestURL);
this.renderer.setAttribute(this.payWithCardIFrame, 'width', '100%');
this.renderer.setAttribute(this.payWithCardIFrame, 'height', '100%');
this.renderer.setAttribute(this.payWithCardIFrame, 'allowTransparency', 'true');
this.renderer.appendChild(this.element.nativeElement, this.payWithCardIFrame);
}
}