# Buyer info component

Use this `drb2b_buyerInfo` component with the `drb2b_taxCertificateCheckout` component. The `drb2b_buyerInfo` publishes an event and the [`drb2b_taxCertificateCheckout` ](https://docs.digitalriver.com/salesforce-lightning/salesforce-lightning-b2b-commerce-app-1.6/extend-the-salesforce-lightning-app/customizing-the-lightning-web-components/components/tax-certificate-component)listens for the event triggered by the `drb2b_buyerInfo` component. The `drb2b_taxCertificateCheckout` is dependent on the `drb2b_buyerInfo` component.

If you use a custom component instead of the `drb2b_buyerinfo` component, you must:

* Populate the following fields in the `WebCart` object:
  * `digitalriverv3__Buyer_Name__c`
  * `digitalriverv3__Buyer_Email__c`
  * `digitalriverv3__Buyer_Phone__c`
  * `digitalriverv3__BillingAddress`
  * `digitalriverv3__DR_Customer_Type__c`
  * `digitalriverv3__Buyer_OrganizationName__c`\
    \
    **Note:** If you choose to use a custom component, make sure you validate that the `digitalriverv3__Buyer_Name__c` field contains a space. Digital River expects both a First Name and Last Name and does a split on this field by looking for a space, ' ' ,value.\
    \
    **Note:** If you use the Buyer Info component, you are not required to make changes as the field is automatically displayed. If you are not using the Buyer Info component, use a field in your user interface to collect the Organization Name information if the shopper's purchase type is Business. This UI field is used to update the `digitalriverv3__Buyer_OrganizationName__c` field on the WebCart object.<br>
* Provide the selected ship-to contact point address ID to the OOTB flow, which populates the ship-to address on the Cart Delivery Group object.

## Publish events

This section provides information on publishing events when using this component.

Use the following steps to publish various event types. The event purpose and payload will vary depending on your use case.

Import the`DigitalRiverMessageChannel__c` message channel and message service into a custom JavaScript file, as shown below.

{% code title="Import example" %}

```
import dr_lms from "@salesforce/messageChannel/digitalriverv3__DigitalRiverMessageChannel__c";

import {publish, MessageContext } from "lightning/messageService";

```

{% endcode %}

Declare the message context variable as shown below.

{% code title="Declare variable example" %}

```
@wire(MessageContext) messageContext;
```

{% endcode %}

Publish the event.

{% code title="Publish example" %}

```
  publish(this.messageContext, dr_lms, { 
                    purpose: '<purpose>',           
                    payload: '<payload>'            
                });

```

{% endcode %}

The following table provides more information on the component events.

| Event Purpose         | Event Payload Example | Description                                                                                                                                                                                                                                                                                                                                                   |
| --------------------- | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| toggleShowBIComponent | `{"isShow":true}`     | Publish this event to show `{"isShow":true}` or hide `{"isShow":false}` the Buyer Info component.                                                                                                                                                                                                                                                             |
| saveBuyerInfo         | n/a                   | <p>Publish this event to perform validation of the information entered into the buyer info component and save the data to the cart. </p><p> </p><p>If publishing this event, you must also subscribe to the contactPointAddressId event to get back the saved Contact Point Address Id.</p><p> </p><p>Use this event if the OOTB Next button is disabled.</p> |

## Subscribe to an event to get Contact Point Address Id

You can use this event to have the saved Contact Point Address Id returned after the buyer information is saved using the saveBuyerInfo purpose. You use this value to update the Cart Delivery Group as appropriate. Complete the following tasks to subscribe to the event.

Import the `DigitalRiverMessageChannel__c` message channel and message service into a custom JavaScript file, as shown below.

{% code title="Import example" %}

```
import dr_lms from "@salesforce/messageChannel/digitalriverv3__DigitalRiverMessageChannel__c";

import {publish, MessageContext } from "lightning/messageService";
```

{% endcode %}

Declare the message context variable as shown below.

{% code title="Declare variable example" %}

```
@wire(MessageContext) messageContext;
```

{% endcode %}

Declare methods as shown below to get the Contact Point Address Id.&#x20;

{% code title="Declare methods example" %}

```
subscribeToMessageChannel() {
        if (!this.subscription) {
            this.subscription = subscribe(this.messageContext, dr_lms,               (message) => this.handleMessage(message));
        }
    }

   handleMessage(message) {
        switch (message.purpose) {
            case " contactPointAddressId":
               // Call custom logic here 
               // message.payload will give Contact point address Id
                break;
        }
    }

```

{% endcode %}

The following is an example of the message format:

{% code title="Message example:" %}

```
{"purpose":"contactPointAddressId","payload":"8lW5Y000000Pz69UAC"}
```

{% endcode %}

Call a declared method in the connectedCallback method as shown below:

{% code title="Call declared method" %}

```
connectedCallback() {
        this.subscribeToMessageChannel();
  
```

{% endcode %}
