ng-shopping-cart
Version:
An Angular component library to create shopping carts
126 lines (125 loc) • 4.61 kB
TypeScript
import { EventEmitter, OnChanges, OnDestroy, OnInit, SimpleChanges } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { CheckoutSettings, CheckoutType } from '../../types';
import { CartService } from '../../services/cart.service';
import { CheckoutPaypalSettings } from '../../interfaces/checkout-paypal-settings';
import { CheckoutHttpSettings } from '../../interfaces/checkout-http-settings';
import { LocaleFormat } from '../../interfaces/locale-format';
/**
* Renders a button to initiate checkout of the cart.
*
* @order 6
* @howToUse "With a custom button or projected content"
* ```html
* <cart-checkout [custom]="true">
* <button type="button" class="my-custom-class">Do checkout</button>
* </cart-checkout>
* ```
*
* @howToUse "With different text and classes"
* ```html
* <cart-checkout [buttonText]="'Add item'" [buttonClass]="'my-custom-class'">
* </cart-checkout>
* ```
*
* @howToUse "Using http in a protected endpoint"
* ```html
* <cart-checkout [service]="'http'" settings="settings">
* </cart-checkout>
* ```
* ```typescript
* export class MyComponent {
* settings: CheckoutHttpSettings = {
* method: 'POST',
* url: 'http://myapi.com/',
* options: { headers: { Authorization: 'Bearer my-auth-token' } }
* };
* }
* ```
*
* @howToUse "Using the PayPal service"
* ```html
* <cart-checkout [service]="'paypal'" settings="settings">
* </cart-checkout>
* ```
* ```typescript
* export class MyComponent {
* settings: CheckoutPaypalSettings = {
* business: 'myaccount@paypal.com',
* itemName: 'myMarketplaceAppCart',
* itemNumber: '1234',
* serviceName: 'MyBusiness',
* country: 'US'
* };
* }
* ```
*
* @note {warning} This component captures clicks events bubbling from its projected content. Make sure the event keeps bubbling only when
* you want the checkout operation to start.
*
* @note {warning} When the `[service]` is set to `paypal` an actual PayPal button is rendered. None of the inputs `custom`, `buttonText`
* or `buttonClass` have any effect.
*/
export declare class CartCheckoutComponent implements OnChanges, OnInit, OnDestroy {
private cartService;
private httpClient;
private locale;
private _serviceSubscription;
private getLocaleCurrencyName;
empty: boolean;
cost: number;
taxRate: number;
shipping: number;
httpSettings: CheckoutHttpSettings;
paypalSettings: CheckoutPaypalSettings;
format: LocaleFormat;
currency: string;
paypalLocale: string;
/**
* If `false` displays a default button provided by the component. When set to `true` projects the contents of the component.
*/
custom: boolean;
/**
* Changes the default text of the component's button.
*/
buttonText: string;
/**
* Changes the default text of the component's button.
*/
buttonClass: string;
/**
* Sets the type of service to be used when initiating the checkout.
*/
service: CheckoutType;
/**
* Depending on the type of the service you might need to add some configuration to it. This input allows you to change that
* configuration.
*/
settings: CheckoutSettings;
/**
* Changes currency display format for the component. Overrides the value set from the service using `setCurrencyFormat`.
*/
localeFormat: string;
/**
* Emits the result of the checkout operation. If the service is set to `'log'` it emits the entire cart object including tax rates and
* shipping info. If is set to `'http'` it emits an `HttpResponse` object with body, headers, etc as it was received by the remote server.
*
* > When `[service]` is set to `'paypal'` this event is never emitted.
*/
checkout: EventEmitter<any>;
/**
* When the `[service]` is set to `'http'` and the checkout operation fails the thrown error can be captured using this output.
*
* The emitted value is the complete `HttpErrorResponse` object returned by `HttpClient` so you can inspect other properties like status
* codes, headers, messages, etc.
*/
error: EventEmitter<any>;
constructor(cartService: CartService<any>, httpClient: HttpClient, locale: string);
ngOnInit(): void;
private updateCart(formatChange);
private updateLocale();
private getCurrency(locale);
doCheckout(): void;
ngOnChanges(changes: SimpleChanges): void;
ngOnDestroy(): void;
}