magento2
magento2 copied to clipboard
magento/magento2#37983: Place order with disabled Payment method working
- prevent order placement with unavailable payment method
Description (*)
I will leave here examples of mutations that I used.
createCustomer
mutation {
createCustomer(
input: {
firstname: "Test"
lastname: "User"
email: "[email protected]"
password: "Password123"
}
) {
customer {
id
email
}
}
}
generateCustomerToken
mutation {
generateCustomerToken(
email: "[email protected]"
password: "Password123"
) {
token
}
}
createEmptyCart (don't forget about Authentification)
mutation {
createEmptyCart
}
addSimpleProductsToCart
mutation {
addSimpleProductsToCart(
input: {
cart_id: "SOMEID" # Replace with the ID from Step 3
cart_items: [
{
data: {
quantity: 1
sku: "test2" # Replace with an actual product SKU from your store
}
}
]
}
) {
cart {
items {
product {
name
sku
}
quantity
}
}
}
}
setShippingAddressesOnCart
mutation {
setShippingAddressesOnCart(
input: {
cart_id: "SOMEID" # Replace with the ID from Step 3
shipping_addresses: [
{
address: {
firstname: "Test"
lastname: "User"
company: "Company Name"
street: ["123 Main Street"]
city: "New York"
region: "NY"
postcode: "10001"
country_code: "US"
telephone: "1234567890"
save_in_address_book: false
}
}
]
}
) {
cart {
shipping_addresses {
firstname
lastname
street
city
region {
code
label
}
postcode
country {
code
label
}
telephone
}
}
}
}
setBillingAddressOnCart
mutation {
setBillingAddressOnCart(
input: {
cart_id: "SOMEID" # Replace with the ID from Step 3
billing_address: {
address: {
firstname: "Test"
lastname: "User"
company: "Company Name"
street: ["123 Main Street"]
city: "New York"
region: "NY"
postcode: "10001"
country_code: "US"
telephone: "1234567890"
save_in_address_book: false
}
same_as_shipping: false
}
}
) {
cart {
billing_address {
firstname
lastname
street
city
region {
code
label
}
postcode
country {
code
label
}
telephone
}
}
}
}
setShippingMethodsOnCart
mutation {
setShippingMethodsOnCart(
input: {
cart_id: "SOMEID" # Replace with the ID from Step 3
shipping_methods: [
{
carrier_code: "flatrate"
method_code: "flatrate"
}
]
}
) {
cart {
shipping_addresses {
selected_shipping_method {
carrier_code
method_code
carrier_title
method_title
}
}
}
}
}
setPaymentMethodOnCart + placeOrder
mutation setPaymentMethodAndPlaceOrder(
$cartId: String!
$paymentMethod: PaymentMethodInput!
) {
setPaymentMethodOnCart(
input: { cart_id: $cartId, payment_method: $paymentMethod }
) {
cart {
selected_payment_method {
code
title
}
}
}
placeOrder(input: { cart_id: $cartId }) {
order {
order_number
}
}
}
VARIABLES
{
"cartId": "SOMEID",
"paymentMethod": {
"code": "checkmo"
}
}
Related Pull Requests
Fixed Issues (if relevant)
- Fixes magento/magento2#37983
Manual testing scenarios (*)
- Disable the checkmo payment method in admin
- Create a quote using GraphQL
- Set addresses and shipping method in GraphQL
- Use a combined mutation with setPaymentMethodOnCart and placeOrder
- Observe that despite the payment method error, an order is still created
Questions or comments
Contribution checklist (*)
- [ ] Pull request has a meaningful description of its purpose
- [ ] All commits are accompanied by meaningful commit messages
- [ ] All new or changed code is covered with unit/integration tests (if applicable)
- [ ] README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
- [ ] All automated tests passed successfully (all builds are green)