blassa-address-verification-button-angular
v0.0.2
Published
This Angular library provides a component for verifying addresses using the Blassa Address Verify service.
Downloads
2
Readme
Blassa Address Verification Angular Library
This Angular library provides a component for verifying addresses using the Blassa Address Verify service.
Installation
To use this library in your Angular application, you need to follow these steps:
Install the library using npm:
npm install blassa-address-verification-button-angular
Authentication
Before you can use the button you need to generate your id token based on your account’s username and password:
import { CognitoIdentityProviderClient, InitiateAuthCommand } from '@aws-sdk/client-cognito-identity-provider';
GenerateApiToken() {
const client = new CognitoIdentityProviderClient({ region: <INSERT_REGION> });
const command = new InitiateAuthCommand({
AuthFlow: "USER_PASSWORD_AUTH",
ClientId: <INSERT_BLASSA_CLIENT_ID_FOR_STAGE>,
AuthParameters: {
USERNAME: <INSERT_USERNAME>,
PASSWORD: <INSERT_PWD>
}
});
try {
console.log('Generating Auth token');
const response = await client.send(command);
return response.AuthenticationResult.IdToken;
} catch (err) {
console.error('Failed to generate token', { err });
throw new Error('Failed to generate token');
}
}
Usage
Now, you can use the lib-blassa-address-verification-button-angular
component in your Angular templates.
Basic Example
// Import necessary dependencies in your component
import { Component } from '@angular/core';
import {
BlassaAddressVerificationComponent,
IBlassaAddressVerificationRequest,
} from 'blassa-address-verification-button-angular';
import { AxiosResponse } from 'axios';
@Component({
selector: 'app-your-component',
imports: [...,BlassaAddressVerificationComponent],
template: `
<lib-blassa-address-verification-button-angular
[apiToken]="yourApiToken"
[createAddressRequestJobBody]="createAddressRequestJobBody"
(createAddressRequestJobResponse)="onCreateAddressRequestJobResponse($event)"
></lib-blassa-address-verification-button-angular>
`,
})
export class YourComponent {
yourApiToken = 'insert_your_api_token_here';
createAddressRequestJobBody: IBlassaAddressVerificationRequest = {
// ... provide order details here
type: 'PRE_CHECKOUT',
customerDetails: {
firstName: 'John',
lastName: 'Doe',
phoneNumber: '+212682519623', // must provide country code
email: '[email protected]', // optional
},
orderDetails: {
orderSource: 'Your Company Name',
description: 'Product details', // optional
},
deliveryDetails: {
countryCode: 'MA',
addressFields: { // optional
city: 'Marrakesh', // optional
street: 'Avenue Mohamed V', // optional
buildingNumber: '775', // optional
postalCode: '2500', // optional
},
};
}
onCreateAddressRequestJobResponse(response: AxiosResponse): void {
console.log('Address info response:', response);
// Handle the response as needed
}
}
Component Inputs
- apiToken (string): Your Blassa Address Verify API key.
- createAddressRequestJobBody (object): An object that provides customerDetails,orderDetails,delieveryDetails for address verifying.
- addressInfoResponse (event): An event emitted with the address information response.
Development
To contribute to the development of this library, follow these steps:
Clone the repository:
git clone https://github.com/your-username/blassa-address-verification-button-angular.git
Install dependencies:
cd blassa-address-verification-button-angular npm install
Make changes and test:
ng serve
Build the library:
ng build blassa-address-verification-button-angular
The built library will be available in the
dist/
directory.
License
This library is licensed under the MIT License - see the LICENSE file for details.