This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate available payment methods before attempting payment or updat…
…ing order statuses (#5440) * Make payment method required * removed unused imports * Remove PUT method * Validate available method when updating order * Enable bacs for tests
- Loading branch information
1 parent
a1e2af7
commit b8de0ab
Showing
5 changed files
with
146 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ The checkout API facilitates the creation of orders (from the current cart) and | |
All checkout endpoints require [Nonce Tokens](nonce-tokens.md). | ||
|
||
- [Get Checkout Data](#get-checkout-data) | ||
- [Update Checkout Data](#update-checkout-data) | ||
- [Process Order and Payment](#process-order-and-payment) | ||
|
||
## Get Checkout Data | ||
|
@@ -28,70 +27,48 @@ curl --header "X-WC-Store-API-Nonce: 12345" --request GET https://example-store. | |
|
||
```json | ||
{ | ||
"order_id": 146, | ||
"status": "checkout-draft", | ||
"order_key": "wc_order_VPffqyvgWVqWL", | ||
"customer_note": "", | ||
"customer_id": 1, | ||
"billing_address": { | ||
"first_name": "Peter", | ||
"last_name": "Venkman", | ||
"company": "", | ||
"address_1": "550 Central Park West", | ||
"address_2": "Corner Penthouse Spook Central", | ||
"city": "New York", | ||
"state": "NY", | ||
"postcode": "10023", | ||
"country": "US", | ||
"email": "[email protected]", | ||
"phone": "555-2368" | ||
}, | ||
"shipping_address": { | ||
"first_name": "Peter", | ||
"last_name": "Venkman", | ||
"company": "", | ||
"address_1": "550 Central Park West", | ||
"address_2": "Corner Penthouse Spook Central", | ||
"city": "New York", | ||
"state": "NY", | ||
"postcode": "10023", | ||
"country": "US" | ||
}, | ||
"payment_method": "", | ||
"payment_result": { | ||
"payment_status": "", | ||
"payment_details": [], | ||
"redirect_url": "" | ||
} | ||
"order_id": 146, | ||
"status": "checkout-draft", | ||
"order_key": "wc_order_VPffqyvgWVqWL", | ||
"customer_note": "", | ||
"customer_id": 1, | ||
"billing_address": { | ||
"first_name": "Peter", | ||
"last_name": "Venkman", | ||
"company": "", | ||
"address_1": "550 Central Park West", | ||
"address_2": "Corner Penthouse Spook Central", | ||
"city": "New York", | ||
"state": "NY", | ||
"postcode": "10023", | ||
"country": "US", | ||
"email": "[email protected]", | ||
"phone": "555-2368" | ||
}, | ||
"shipping_address": { | ||
"first_name": "Peter", | ||
"last_name": "Venkman", | ||
"company": "", | ||
"address_1": "550 Central Park West", | ||
"address_2": "Corner Penthouse Spook Central", | ||
"city": "New York", | ||
"state": "NY", | ||
"postcode": "10023", | ||
"country": "US" | ||
}, | ||
"payment_method": "", | ||
"payment_result": { | ||
"payment_status": "", | ||
"payment_details": [], | ||
"redirect_url": "" | ||
} | ||
} | ||
``` | ||
|
||
## Update Checkout Data | ||
|
||
Allows the client to update checkout data, and returns an updated response. | ||
|
||
This endpoint will return an error unless a valid [Nonce Token](nonce-tokens.md) is provided. | ||
|
||
```http | ||
PUT /wc/store/checkout | ||
``` | ||
|
||
| Attribute | Type | Required | Description | | ||
| :----------------- | :------ | :------: | :-------------------------------------------------------------- | | ||
| `billing_address` | array | No | Array of updated billing address data for the customer. | | ||
| `shipping_address` | integer | No | Array of updated shipping address data for the customer. | | ||
| `customer_note` | string | No | Note added to the order by the customer during checkout. | | ||
| `payment_method` | string | No | The ID of the payment method being used to process the payment. | | ||
|
||
```http | ||
curl --header "X-WC-Store-API-Nonce: 12345" --request PUT https://example-store.com/wp-json/wc/store/checkout?payment_method=paypal | ||
``` | ||
|
||
Returns either updated checkout data (See [Get Checkout Data](#get-checkout-data)), or an error response. | ||
|
||
## Process Order and Payment | ||
|
||
Posts final checkout data, including data from payment methods, and attempts payment. | ||
Accepts the final customer addresses and chosen payment method, and any additional payment data, then attempts payment and | ||
returns the result. | ||
|
||
This endpoint will return an error unless a valid [Nonce Token](nonce-tokens.md) is provided. | ||
|
||
|
@@ -101,10 +78,10 @@ POST /wc/store/checkout | |
|
||
| Attribute | Type | Required | Description | | ||
| :----------------- | :------ | :------: | :------------------------------------------------------------------ | | ||
| `billing_address` | array | No | Array of updated billing address data for the customer. | | ||
| `shipping_address` | integer | No | Array of updated shipping address data for the customer. | | ||
| `billing_address` | array | Yes | Array of updated billing address data for the customer. | | ||
| `shipping_address` | integer | Yes | Array of updated shipping address data for the customer. | | ||
| `customer_note` | string | No | Note added to the order by the customer during checkout. | | ||
| `payment_method` | string | No | The ID of the payment method being used to process the payment. | | ||
| `payment_method` | string | Yes | The ID of the payment method being used to process the payment. | | ||
| `payment_data` | array | No | Data to pass through to the payment method when processing payment. | | ||
|
||
```http | ||
|
@@ -115,40 +92,40 @@ curl --header "X-WC-Store-API-Nonce: 12345" --request POST https://example-store | |
|
||
```json | ||
{ | ||
"order_id": 146, | ||
"status": "on-hold", | ||
"order_key": "wc_order_VPffqyvgWVqWL", | ||
"customer_note": "", | ||
"customer_id": 1, | ||
"billing_address": { | ||
"first_name": "Peter", | ||
"last_name": "Venkman", | ||
"company": "", | ||
"address_1": "550 Central Park West", | ||
"address_2": "Corner Penthouse Spook Central", | ||
"city": "New York", | ||
"state": "NY", | ||
"postcode": "10023", | ||
"country": "US", | ||
"email": "[email protected]", | ||
"phone": "555-2368" | ||
}, | ||
"shipping_address": { | ||
"first_name": "Peter", | ||
"last_name": "Venkman", | ||
"company": "", | ||
"address_1": "550 Central Park West", | ||
"address_2": "Corner Penthouse Spook Central", | ||
"city": "New York", | ||
"state": "NY", | ||
"postcode": "10023", | ||
"country": "US" | ||
}, | ||
"payment_method": "cheque", | ||
"payment_result": { | ||
"payment_status": "success", | ||
"payment_details": [], | ||
"redirect_url": "https:\/\/local.wordpress.test\/block-checkout\/order-received\/146\/?key=wc_order_VPffqyvgWVqWL" | ||
} | ||
"order_id": 146, | ||
"status": "on-hold", | ||
"order_key": "wc_order_VPffqyvgWVqWL", | ||
"customer_note": "", | ||
"customer_id": 1, | ||
"billing_address": { | ||
"first_name": "Peter", | ||
"last_name": "Venkman", | ||
"company": "", | ||
"address_1": "550 Central Park West", | ||
"address_2": "Corner Penthouse Spook Central", | ||
"city": "New York", | ||
"state": "NY", | ||
"postcode": "10023", | ||
"country": "US", | ||
"email": "[email protected]", | ||
"phone": "555-2368" | ||
}, | ||
"shipping_address": { | ||
"first_name": "Peter", | ||
"last_name": "Venkman", | ||
"company": "", | ||
"address_1": "550 Central Park West", | ||
"address_2": "Corner Penthouse Spook Central", | ||
"city": "New York", | ||
"state": "NY", | ||
"postcode": "10023", | ||
"country": "US" | ||
}, | ||
"payment_method": "cheque", | ||
"payment_result": { | ||
"payment_status": "success", | ||
"payment_details": [], | ||
"redirect_url": "https://local.wordpress.test/block-checkout/order-received/146/?key=wc_order_VPffqyvgWVqWL" | ||
} | ||
} | ||
``` |
Oops, something went wrong.