# Payment Intents

## The Payment Intent Resource

A `PaymentIntent` resource is used to track and handle different states of the payment until it succeeds. To learn how to receive credit/debit card payments using PaymentIntent, you can check this [section](https://developers.paymongo.com/docs/accepting-cards). To learn how to receive PayMaya payments using PaymentIntent, you can check this [section](https://developers.paymongo.com/docs/accepting-paymaya-payments).

[More Details](https://developers.paymongo.com/reference/the-payment-intent-object)

## Creating a Payment Intent

```javascript
/**
 * These are the required properties
 * @param {Object} data The payload.
 * @param {Object} data.attributes Payload attributes.
 * @param {number} data.attributes.amount Amount to be collected by the PaymentIntent.
 * @param {string[]} data.attributes.payment_method_allowed The list of payment method types that the PaymentIntent is allowed to use. Possible value is card for now.
 * @param {string} data.attributes.currency Three-letter ISO currency code, in uppercase. PHP is the only supported currency as of the moment.
 */
const result = await paymongo.paymentIntents.create(data);

```

#### Payload

```javascript
{
  data: {
    attributes: {
      amount: 10000, // 10000 or 100 in money value is the smallest allowed amount.
      currency: 'PHP', // Three-letter ISO currency code. Only supports PHP for now.
      payment_method_allowed: ['card'] // The only available value for now is 'card'.
    }
  }
}

```

## Retrieving a Payment Intent

```javascript
/**
 * @param {string} id PaymentIntent id
 */
const result = await paymongo.paymentIntents.retrieve(id);

```

#### Attach to PaymentIntent

```javascript
/**
 * These are the required properties
 * @param {string} id PaymentIntent id.
 * @param {Object} data The payload.
 * @param {Object} data.attributes Payload attributes.
 * @param {string} data.attributes.payment_method Id of PaymentMethod to attach to the PaymentIntent.
 */
const result = await paymongo.paymentIntents.attach(id, data);

```

#### Payload

```javascript
{
  data: {
    attributes: {
      payment_method: 'abc123'
    }
  }
}

```

## Capture a PaymentIntent

```javascript
/**
 * @param {string} secret API private key
 * @param {string} id PaymentIntent id
 */
const result = await paymongo.paymentIntents.capture(id);
```

## Cancel a PaymentIntent

```javascript
/**
 * @param {string} secret API private key
 * @param {string} id PaymentIntent id
 */
const result = await paymongo.paymentIntents.cancel(id);
```
