
import CustomerPickupInfoFields from "../../../src/reference/subbly-sdk/types/CustomerPickupInfo.mdx";

<SdkPage group="pickup-info" />

<Method id="list" signature="subbly.pickupInfo.list(params)">

Gets the pick-up contact records the signed-in customer saved. A record says who
collects the parcel, and which point they collect it from. Needs an
authenticated customer.

<Params>
  <Param name="params" required type="PickupInfoFetchParams">
    Which records to return. The argument is required by position, so pass an
    empty object for all of them.
    <Properties label="params">
      <Param name="shippingMethodId" optional type="number">
        Keep only the records that work with this pick-up shipping method. In
        practice this filters by country.
      </Param>
    </Properties>
  </Param>
</Params>

<Returns type="Promise<CustomerPickupInfo[]>">
The saved records.
<Properties label="record" collapsed>
  <CustomerPickupInfoFields />
</Properties>
</Returns>

<Example>

```js title="List every record"
const pickupInfos = await subbly.pickupInfo.list({})
```

```js title="List the records for one pick-up method"
const [method] = await subbly.cart.getLocalPickups()
const pickupInfos = await subbly.pickupInfo.list({ shippingMethodId: method.id })
```

</Example>

</Method>

<Method id="store" signature="subbly.pickupInfo.store(payload)">

Creates a pick-up contact record for the signed-in customer. Put its `id` on the
cart as `shippingAddressId` once the customer chose a pick-up point. Needs an
authenticated customer.

<Params>
  <Param name="payload" required type="PickupInfoStorePayload">
    The record to create.
    <Properties label="payload">
      <Param name="firstName" required type="string">
        Given name of the person who collects the parcel.
      </Param>

      <Param name="lastName" required type="string">
        Family name of that person.
      </Param>

      <Param name="phone" required type="string">
        Phone number of that person.
      </Param>

      <Param name="pickupPointType" optional type="'mondial_relay'">
        Set this only for a point in an external network. `mondial_relay` is
        the one value the field takes.
      </Param>

      <Param name="pickupPointId" optional type="string">
        ID of the point in that external network.
      </Param>
    </Properties>
  </Param>
</Params>

<Returns type="Promise<CustomerPickupInfo>">
The record created.
<Properties label="record" collapsed>
  <CustomerPickupInfoFields />
</Properties>
</Returns>

<Example>

```js title="Add a record"
const pickupInfo = await subbly.pickupInfo.store({
  firstName: 'Ada',
  lastName: 'Lovelace',
  phone: '+15551234567'
})

await subbly.cart.update({ shippingAddressId: pickupInfo.id })
```

```js title="Add a record for a Mondial Relay point"
await subbly.pickupInfo.store({
  firstName: 'Ada',
  lastName: 'Lovelace',
  phone: '+33123456789',
  pickupPointType: 'mondial_relay',
  pickupPointId: '005670'
})
```

</Example>

</Method>

<Method id="delete" signature="subbly.pickupInfo.delete(pickupInfoId)">

Deletes a pick-up contact record. Needs an authenticated customer. The request
fails while a subscription still uses the record.

<Params>
  <Param name="pickupInfoId" required type="number">
    ID of the record to delete.
  </Param>
</Params>

<Returns type="Promise<void>">
Nothing. The response body is empty.
</Returns>

<Example>

```js title="Delete a record"
await subbly.pickupInfo.delete(123)
```

</Example>

</Method>
