> For the complete documentation index, see [llms.txt](https://apidocs.akinon.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://apidocs.akinon.com/commerce/checkout/payment-related.md).

# Payment Related

This document covers all services for payment-related checkout, including the requests and responses associated with these services.

{% hint style="warning" %}
**Authenticated Endpoints**

Accessing authenticated endpoints requires users to establish a session through Session Authentication. To do this:

1. Users must log in using their credentials (e.g., username and password) via a designated authentication endpoint.
2. Upon successful login, the server will generate and return a session cookie to the client.
3. This session cookie must be included in subsequent API requests as part of the headers. The session cookie serves as proof of authentication and ensures secure access to protected resources.
   {% endhint %}

### `GET` Available Payment Options

This method is used to get a list for all available payment options.

**Path:** `https://{commerce_url}/orders/checkout/?page=PaymentOptionSelectionPage`

The following `payment_option` are currently available:

```
credit_card 	=> 'Credit Card'
funds_transfer 	=> 'Funds Transfer'
pay_on_delivery => 'Pay On Delivery'
bkm_express 	=> 'BKM Express'
loyalty_money 	=> 'Store Credit'
cash_register 	=> 'Cash Register'
gpay 			=> 'Garanti Pay'
redirection 	=> "Redirect to Bank"
stored_card 	=> 'Stored Card'
masterpass 		=> 'Masterpass'
credit_payment 	=> 'Credit Payment'
saved_card		=> 'Saved Card'
pay_later		=> 'Pay Later'
confirmation 	=> 'Confirmation From User'
```

**Example Request**

```python
import requests

url = "https://{commerce_url}/orders/checkout/?page=PaymentOptionSelectionPage"

payload = 'payment_option=<pk>'
headers = {
  'x-requested-with': 'XMLHttpRequest',
  'Cookie': 'osessionid=<session_id>',
  'Content-Type': 'application/x-www-form-urlencoded'
}

response = requests.request("GET", url, headers=headers, data=payload)

print(response.text)
```

**Example Response**

```json
    {
    	"context_list": [
        	{
				"page_context": {
					"checkout_url": "https://{commerce_url}/checkout-with-token/<UNIQUE_CHECKOUT_TOKEN>",
					"status_url": "https://{commerce_url}/checkout-with-token/<UNIQUE_CHECKOUT_TOKEN>/status/",
					"payment_options": [
						{
							"pk": 1,
							"name": "credit_card",
							"slug": "credit_card",
							"payment_type": "credit_card",
							"payment_type_label": "Credit Card",
						}
					],
					"unavailable_options": [
						{
							"name": "Redirect to Bank",
							"slug": "redirection",
							"payment_type": "redirection",
							"payment_type_label": "Redirect to Bank",
							"error_code": 1000,
							"error_message": "Some error message about why the option is not available.",
						}
					]
				},
				"page_name": "PaymentOptionSelectionPage",
				"page_slug": "PaymentOptionSelectionPage"
			}
    	],
    	"template_name": "orders/checkout.html",
    	"errors": null,
    	"pre_order": {...}
    }
```

### `POST` Set Payment Option

This method is used to set the selected payment option to the current pre-order.

**Path:** `https://{commerce_url}/orders/checkout/?page=PaymentOptionSelectionPage`

The endpoint result may vary depending on the selected payment option. Thus, the next page could be one of the following:

* BinNumberPage
* FundsTransferChoicePage
* BexSelectionPage
* LoyaltyMoneyPage
* CashRegisterPage
* PaySelectionPage
* RedirectionPaymentSelectedPage
* MobilExpressSelectionPage
* MasterpassBinNumberPage
* CreditPaymentSelectionPage
* PayLaterCompletePage
* SavedCardSelectionPage
* ConfirmationPaymentAgreementCheckPage

**Example Request**

```python
import requests

url = "https://{commerce_url}/orders/checkout/?page=PaymentOptionSelectionPage"

payload = 'payment_option=1'
headers = {
  'x-requested-with': 'XMLHttpRequest',
  'Cookie': 'osessionid=<session_id>',
  'Content-Type': 'application/x-www-form-urlencoded'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
```

**Example Response**

```json
    {
    	"context_list": [
        	{
				"page_context": {
					// page_context differs according to the payment option selection
					// explained in payment strategy related documentation
				},
				"page_name": "PaymentOptionSelectionPage",
				"page_slug": "PaymentOptionSelectionPage"
			}
    	],
    	"template_name": "orders/checkout.html",
    	"errors": null,
    	"pre_order": {...}
    }
```

**Example Response - Pay on Delivery**

When the user selects "Pay on Delivery" as the payment option, the following endpoint response is returned.

```json
    {
    	"context_list": [
        	{
				"page_context": {
					"payment_choices": [
						{
							"label": "Kredi Karti",
							"sku": "00001",
							"value": "credit_card"
						},
						{
							"label": "Pesin",
							"sku": "00002",
							"value": "cash"
						}
					]
				},
				"page_name": "PayOnDeliveryPaymentChoicePage",
				"page_slug": "PayOnDeliveryPaymentChoicePage"
			}
    	],
    	"template_name": "orders/checkout.html",
    	"errors": null,
    	"pre_order": {...}
    }
```

### `POST` Set Payment Choice

This method is used to set the selected payment option (Pay on Delivery) to the current pre-order.

**Path:** `https://{commerce_url}/orders/checkout/?page=PayOnDeliveryPaymentChoicePage`

The endpoint result may vary depending on "sms verification", "Pay on Delivery" configuration option.

**Example Request**

```python
import requests

url = "https://{commerce_url}/orders/checkout/?page=PayOnDeliveryPaymentChoicePage"

payload = 'payment_choice=cash'
headers = {
  'x-requested-with': 'XMLHttpRequest',
  'Cookie': 'osessionid=<session_id>',
  'Content-Type': 'application/x-www-form-urlencoded'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
```

**Example Response - SMS Verification Required**

```json
    {
    	"context_list": [
        	{
				"page_context": {
					"verification": true,
				},
				"page_name": "VerifySmsPage",
				"page_slug": "VerifySmsPage"
			},
    	],
    	"template_name": "orders/checkout.html",
    	"errors": null,
    	"pre_order": {...}
    }
```

**Example Response - SMS Verification Disabled**

```json
    {
    	"context_list": [
			{
				"page_context": {

				},
				"page_name": "ThankYouPage",
				"page_slug": "ThankYouPage"
			}
    	],
    	"template_name": "orders/checkout.html",
    	"errors": null,
    	"pre_order": {...}
    }
```

### `POST` SMS Verification

This method is used to set the verification code for SMS verification.

**Path:** `https://{commerce_url}/orders/checkout/?page=VerifySmsPage`

**Example Request**

```python
import requests

url = "https://{commerce_url}/orders/checkout/?page=VerifySmsPage"

payload = 'verify_code=123456'
headers = {
  'x-requested-with': 'XMLHttpRequest',
  'Cookie': 'osessionid=<session_id>',
  'Content-Type': 'application/x-www-form-urlencoded'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
```

**Example Response**

```json
    {
    	"context_list": [
			{
				"page_context": {
						"verification_sent_datetime": "2023-03-15 15:00:00+00:00",
						"seconds_left": 39,
						"retry": true,
				},
				"page_name": "ThankYouPage",
				"page_slug": "ThankYouPage"
			}
    	],
    	"template_name": "orders/checkout.html",
    	"errors": null,
    	"pre_order": {...}
    }
```

### `GET` Created Order Information

This method is used to get created order information from pre-order.

**Path:** `https://{commerce_url}/orders/checkout/?page=ThankYouPage`

**Example Request**

```python
import requests

url = "https://{commerce_url}/orders/checkout/?page=ThankYouPage"

payload = {}
headers = {
  'x-requested-with': 'XMLHttpRequest',
  'Cookie': 'osessionid=<session_id>'
}

response = requests.request("GET", url, headers=headers, data=payload)

print(response.text)
```

**Example Response**

```json
    {
    	"context_list": [
			{
				"page_context": {
					"redirect_url": "https://{commerce_url}/completed/{ORDERNUMBER}",
					"order_id": 123,
					"order_number": "ON123",
					"new_user": false,
					"token": "df8a210c-c19d-4497-ad63-494fdea1f1e0",
					"campaigns": [
						{
							"code": "1", 
							"message": "xyz"
						},
					],
				},
			}
    	],
    	"template_name": "orders/checkout.html",
    	"errors": null,
    	"pre_order": {...}
    }
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://apidocs.akinon.com/commerce/checkout/payment-related.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
