> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gr4vy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Creating transactions

After the buyer selects their method of payment in the previous step, the transaction is ready to be created.

## Create a transaction

The transaction should be populated with the selected `method`, your `redirect_url`, and
any other relevant transaction information.

* `payment_method.method` - This is the method selected by the customer at checkout. This is one of the values retrieved from the payment options endpoint in the previous step.

* `payment_method.redirect_url` - This should be provided to redirect the buyer back to the app after they have authenticated the payment. This is also required for card to support 3-D Secure.

See the [`POST /transactions`](/reference/transactions/new-transaction) API endpoint for more details.

<CodeGroup>
  ```csharp C# theme={"system"}
  var transaction = await client.Transactions.CreateAsync(
      transactionCreate: new TransactionCreate()
      {
          Amount = 1299,
          Currency = "USD",
          Country = "US",
          PaymentMethod =
              TransactionCreatePaymentMethod.CreateCheckoutSessionWithUrlPaymentMethodCreate(
                  new RedirectPaymentMethodCreate()
                  {
                      Method = "clearpay",
                      RedirectUrl = "https://example.com/callback",
                  }
              ),
      }
  );
  ```

  ```go Go theme={"system"}
  amount := int64(1299)
  currency := "USD"
  method := "clearpay"
  redirectUrl: "https://example.com/callback"

  redirectPaymentMethodCreate := components.RedirectPaymentMethodCreate{
      Method: method,
      RedirectUrl: redirectUrl
  }
  paymentMethod := components.CreateTransactionCreatePaymentMethodRedirectPaymentMethodCreate(redirectPaymentMethodCreate)

  transactionCreate := components.TransactionCreate{
      Amount:        amount,
      Currency:      currency,
      PaymentMethod: &paymentMethod,
  }

  transaction, err := client.Transactions.Create(ctx, transactionCreate, nil, nil)

  // handle response
  ```

  ```java Java theme={"system"}
  CreateTransactionResponse transactionResponse = gr4vyClient.transactions().create()
      .transactionCreate(TransactionCreate.builder()
          .amount(1299L)
          .currency("USD")
          .paymentMethod(TransactionCreatePaymentMethod.of(RedirectPaymentMethodCreate.builder()
              .method("clearpay")
              .redirectUrl("https://example.com/callback")
              .build()))
          .build())
      .call();

  Transaction transaction = transactionResponse.transaction().orElse(null);

  // handle response
  ```

  ```php PHP theme={"system"}
  $transactionCreate = new TransactionCreate(amount: 1299, currency: 'USD', paymentMethod: new RedirectPaymentMethodCreate(method: 'clearpay', redirectUrl: 'https://example.com/callback'));
  $response = self::$sdk->transactions->create($transactionCreate);
  $transaction = $response->transaction;
  ```

  ```python Python theme={"system"}
  transaction: models.Transaction = client.transactions.create(
      amount=1299,
      currency="USD",
      payment_method={
          "method": "clearpay",
          "redirect_url": "https://example.com/callback",
      }
  )
  ```

  ```ts TypeScript theme={"system"}
  const transaction = await gr4vy.transactions.create({
      amount: 1299,
      currency: "USD",
      paymentMethod: {
      method: "clearpay",
      redirectUrl: "https://example.com/callback"
    }
  })
  ```
</CodeGroup>

The response of this transaction includes a `status`, which tells you how to handle the
next step.

<Warning>
  Requests that require a redirect return a `status` of `buyer_approval_pending` with a `payment_method.approval_url`. The next step shows you how to handle this situation.
</Warning>

<CodeGroup>
  ```json Response theme={"system"}
  {
      "type": "transaction",
      "id": "0c41c8df-27f4-480e-97f0-9401558ae25e",
      "merchant_account_id": "default",
      "created_at": "2023-04-28T08:33:06.979938+00:00",
      "updated_at": "2023-04-28T08:33:14.791510+00:00",
      "amount": 1299,
      "captured_amount": 0,
      "refunded_amount": 0,
      "currency": "AUD",
      "country": "AU",
      "external_identifier": null,
      "status": "buyer_approval_pending",
      "intent": "authorize",
      "payment_method": {
          "type": "payment-method",
          "method": "paypal",
          "mode": "redirect",
          "label": null,
          "scheme": null,
          "expiration_date": null,
          "approval_url": "https://www.sandbox.paypal.com/checkoutnow?token=7NP38594266148058",
          "country": "AU",
          "currency": "AUD",
          "details": null,
          "id": null,
          "approval_target": "any",
          "external_identifier": null
      },
      "method": "paypal",
      "error_code": null,
      "payment_service": {
          "id": "e9bd6ec4-03eb-410c-b655-45b458f185f2",
          "type": "payment-service",
          "payment_service_definition_id": "paypal-paypal",
          "method": "paypal",
          "display_name": "PayPal"
      },
      "buyer": null,
      "raw_response_code": "CREATED",
      "raw_response_description": "",
      "shipping_details": null,
      "avs_response_code": null,
      "cvv_response_code": null,
      "payment_source": "ecommerce",
      "merchant_initiated": false,
      "is_subsequent_payment": false,
      "cart_items": [],
      "statement_descriptor": null,
      "scheme_transaction_id": null,
      "three_d_secure": null,
      "payment_service_transaction_id": "7NP38594266148058",
      "metadata": null,
      "authorized_at": null,
      "captured_at": null,
      "voided_at": null,
      "buyer_approval_timedout_at": null
  }
  ```
</CodeGroup>

## Summary

In this step you:

* Called the transactions endpoint
* Handled the transaction response
