Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
@ng-web-apis/payment-request
Advanced tools
This is a library for declarative use of Payment Request API with Angular
Angular does not have any abstractions over Payment Request API. This library provides you two ways to use this API with Angular of 6+ version.
If you do not have @ng-web-apis/common:
npm i @ng-web-apis/common
Now install the package:
npm i @ng-web-apis/payment-request
As an Angular service:
import {PaymentRequestService} from '@ng-web-apis/payment-request';
...
constructor(private readonly paymentRequest: PaymentRequestService) {}
pay(details: PaymentDetailsInit) {
this.paymentRequest.request(details).then(
response => {
response.complete();
},
error => {},
);
}
As a set of directives:
<div
waPayment
[paymentTotal]="total"
>
<div
*ngFor="let item of items"
waPaymentItem
[paymentLabel]="item.label"
[paymentAmount]="item.amount"
>
{{item.label}} ({{item.amount}})
</div>
<button
(waPaymentSubmit)="onPaymentSubmit($event)"
(waPaymentError)="onPaymentError($event)"
>
Buy
</button>
</div>
Do not forget to import PaymentRequestModule:
import {PaymentRequestModule} from '@ng-web-apis/payment-request';
...
@NgModule({
...
imports: [
...
PaymentRequestModule
]
})
export class YourModule {}
As a good example of usage you can take a look at a project live demo on CodeSandbox
waPayment directive defines a scope for a new payment and needs PaymentItem object with information about a label and a total sum of the payment
How to use:
<any-element
waPayment
[paymentTotal]="total"
>
...
</any-element>
It implements PaymentDetailsInit
Required inputs:
paymentTotal
is a information about a label and a total sum of the payment as
PaymentItemAdditional inputs:
paymentId
is an id of the payment as string
paymentModifiers
is an array of
PaymentDetailsModifier
paymentShippingOptions
is a
PaymentShippingOption
object for the payment.
Each item of the payment is a waPaymentItem
directive. It is a declarative
PaymentItem for your Payment
How to use:
<any-element
waPayment
[paymentTotal]="total"
>
<any-element
*ngFor="let item of items"
waPaymentItem
[paymentLabel]="item.label"
[paymentAmount]="item.amount"
>
{{item.label}}
</any-element>
</any-element>
It implements PaymentItem
Required inputs:
paymentAmount
is a price of payment item in modal as
PaymentCurrencyAmount
paymentLabel
is a title of payment item in modal as string
Additional inputs:
paymentPending
is native property for PaymentItem as boolean
This directive starts a Payment Request modal in your browser that returns PaymentResponse or an error
How to use:
<any-element
waPayment
[paymentTotal]="total"
>
...
<button
(waPaymentSubmit)="onPayment($event)"
(waPaymentError)="onPaymentError($event)"
>
Buy
</button>
</any-element>
Outputs:
waPaymentSubmit
emits PaymentResponse object to
handle a payment request result
waPaymentError
emits an Error
or DOMException
with information about user's problem that did not allow payment
to proceed
The library also provides some tokens to simplify working with Payment Request API:
PAYMENT_REQUEST_SUPPORT
returns true
if user's browser supports Payment Request APIexport class YourComponent {
constructor(
@Inject(PAYMENT_REQUEST_SUPPORT) private readonly canRequest: boolean
) {}
...
PAYMENT_METHODS
as an array of supported API methods. It uses [{supportedMethods: 'basic-card'}]
by default@Component({
...
providers: [
{
provide: [PAYMENT_METHODS],
useValue: [
// a sample with Google Pay from https://developers.google.com/pay/api/web/guides/paymentrequest/tutorial?hl=en
{supportedMethods: 'https://google.com/pay', data: googlePaymentDataRequest},
{supportedMethods: 'basic-card'}
]
}
]
})
export class YourComponentThatMakesPaymentRequests {
...
}
PAYMENT_OPTIONS
as an object with info that you need about a payer. It uses {}
by default@Component({
...
providers: [
{
provide: [PAYMENT_OPTIONS],
useValue: {
shippingType: 'express',
requestPayerName: true,
requestShipping: true,
requestPayerEmail: true,
}
}
]
})
export class YourComponentThatMakesPaymentRequests {
...
}
12+ | Disabled by default | 61+ | 11.1+ |
All @ng-web-apis for your apps
FAQs
This is a library for declarative use of Payment Request API with Angular
The npm package @ng-web-apis/payment-request receives a total of 23 weekly downloads. As such, @ng-web-apis/payment-request popularity was classified as not popular.
We found that @ng-web-apis/payment-request demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.