Problem with Mutation paymentSessionPending

Solved

Problem with Mutation paymentSessionPending

MiroslavPS
Shopify Partner
3 1 1

Hi guys!
I want to set my order to be Pending (Unpaid) and try to do it like this:

// $id is known and I only set the follow variables:
$pendingExpiresAt = '2024-06-21T13:55:13+00:00'; // php Iso 8601
$reason              = "PARTNER_ACTION_REQUIRED";


postQueryWithVariablesAsync( 'mutation paymentSessionPending($id: ID!, $pendingExpiresAt: DateTime!, $reason: PaymentSessionStatePendingReason!) { paymentSessionPending(id: $id, pendingExpiresAt: $pendingExpiresAt, reason: $reason) { paymentSession { id state nextAction { action context { ... on PaymentSessionActionsRedirect { redirectUrl } } } } userErrors { field message } } }', [ 'id' => "gid://shopify/PaymentSession/$id", 'reason' => [ 'code' => $reason, 'merchantMessage' => 'Waiting payment to be approved.', ], ], $this->rateLimits->graphqlSleepFunction(queryCost: 13) );

And as result I got strange response:
"message": "Variable $pendingExpiresAt of type DateTime! was provided invalid value",
"explanation": "Expected value to not be null"

 

 

"message":"Variable $reason of type PaymentSessionStatePendingReason! was provided invalid value",

"explanation":"Expected "{
"code"=>"PARTNER_ACTION_REQUIRED",
"merchantMessage"=>"Waiting payment to be approved."
}" to be one of: BUYER_ACTION_REQUIRED, PARTNER_ACTION_REQUIRED, NETWORK_ACTION_REQUIRED"}]}}]}

 

Any ideas what I am doing wrong?

Regards!

Accepted Solution (1)
MiroslavPS
Shopify Partner
3 1 1

This is an accepted solution.

I found my mistake - typical copy-paste error. I need to pass the expire time in the second parameter - the array. Also the reason is not an array but simple string:

// $id is known and I only set the follow variables:
$pendingExpiresAt    = '2024-06-21T13:55:13+00:00'; // php Iso 8601
$reason              = "PARTNER_ACTION_REQUIRED";

postQueryWithVariablesAsync(
            'mutation paymentSessionPending($id: ID!, $pendingExpiresAt: DateTime!, $reason: PaymentSessionStatePendingReason!) {
                paymentSessionPending(id: $id, pendingExpiresAt: $pendingExpiresAt, reason: $reason) {
                    paymentSession {
                        id
                        state
                        nextAction {
                            action
                            context {
                                ... on PaymentSessionActionsRedirect {
                                    redirectUrl
                                }
                            }
                        }
                    }
                    userErrors {
                        field
                        message
                    }
                }
            }',
            [
                'id' => "gid://shopify/PaymentSession/$id",
                'pendingExpiresAt' => $pendingExpiresAt,
                'reason' => $reason,
            ], 
            $this->rateLimits->graphqlSleepFunction(queryCost: 13)
        );

View solution in original post

Replies 4 (4)

ketanp
Visitor
3 0 0

The paymentSessionPending mutation in Shopify is typically used to update the state of a payment session to indicate that it is pending further action, such as completion or validation. Problems with this mutation can arise from various issues, such as incorrect input data, permissions, or integration errors.

Here's a detailed guide to help you troubleshoot and solve this issue:

Troubleshooting Steps for paymentSessionPending Mutation in Shopify

1. Check API Documentation and Update

Ensure you are using the latest version of the API and check the Shopify GraphQL API documentation for any updates related to the paymentSessionPending mutation.

 

2. Verify Input Parameters

Ensure that you are providing the correct input parameters for the mutation. The required parameters usually include:

  • id: The ID of the payment session.
  • amount: The amount that is pending.
  • reason: The reason for the pending status (optional).

Example mutation:

 

graphql

 

mutation {
  paymentSessionPending(
    id: "gid://shopify/PaymentSession/{session-id}",
    amount: {
      amount: "10.00",
      currencyCode: USD
    }
  ) {
    paymentSession {
      id
      state
    }
    userErrors {
      field
      message
    }
  }
}

 

 

3. Handle User Errors

Check the userErrors field in the mutation response. This field will provide information about what went wrong if the mutation fails.

Example response with user errors:

 

json

 

{
  "data": {
    "paymentSessionPending": {
      "paymentSession": null,
      "userErrors": [
        {
          "field": ["id"],
          "message": "The provided ID is invalid."
        }
      ]
    }
  }
}

 

 

If you see errors here, correct the issues mentioned.

4. Check Permissions

Ensure that your API key or access token has the necessary permissions to perform the mutation. You might need write_payments permissions.

5. Inspect Payment Session Status

Verify the current status of the payment session. If the session is already completed or canceled, you might not be able to update it to pending.

6. Network and Authentication Issues

  • Network: Ensure there are no network issues that could be interrupting the request.
  • Authentication: Make sure your API requests are properly authenticated using the correct API key or OAuth token.

7. Debugging with Logs

Check your application's logs or Shopify's API logs to see if there are more details about the request failure.

8. Review Shopify Community and Support

Check the Shopify Support for any similar issues or solutions.

Example Workflow

Fetch Payment Session Details:

graphql

 

query {
  paymentSession(id: "gid://shopify/PaymentSession/{session-id}") {
    id
    state
    amount {
      amount
      currencyCode
    }
  }
}

 

 

Update to Pending State:

 

graphql

 

mutation {
  paymentSessionPending(
    id: "gid://shopify/PaymentSession/{session-id}",
    amount: {
      amount: "10.00",
      currencyCode: USD
    }
  ) {
    paymentSession {
      id
      state
    }
    userErrors {
      field
      message
    }
  }
}

 

 

 

MiroslavPS
Shopify Partner
3 1 1

Тhanks for the response!

In Documentation Shopify do not mention amount, but expire date:

 

mutation paymentSessionPending($id: ID!, $pendingExpiresAt: DateTime!, $reason: PaymentSessionStatePendingReason!) {
  paymentSessionPending(id: $id, pendingExpiresAt: $pendingExpiresAt, reason: $reason) {
    paymentSession {
      # PaymentSession fields
    }
    userErrors {
      field
      message
    }
  }
}

 

 but I will try you solution also.

Regards!

MiroslavPS
Shopify Partner
3 1 1

This is an accepted solution.

I found my mistake - typical copy-paste error. I need to pass the expire time in the second parameter - the array. Also the reason is not an array but simple string:

// $id is known and I only set the follow variables:
$pendingExpiresAt    = '2024-06-21T13:55:13+00:00'; // php Iso 8601
$reason              = "PARTNER_ACTION_REQUIRED";

postQueryWithVariablesAsync(
            'mutation paymentSessionPending($id: ID!, $pendingExpiresAt: DateTime!, $reason: PaymentSessionStatePendingReason!) {
                paymentSessionPending(id: $id, pendingExpiresAt: $pendingExpiresAt, reason: $reason) {
                    paymentSession {
                        id
                        state
                        nextAction {
                            action
                            context {
                                ... on PaymentSessionActionsRedirect {
                                    redirectUrl
                                }
                            }
                        }
                    }
                    userErrors {
                        field
                        message
                    }
                }
            }',
            [
                'id' => "gid://shopify/PaymentSession/$id",
                'pendingExpiresAt' => $pendingExpiresAt,
                'reason' => $reason,
            ], 
            $this->rateLimits->graphqlSleepFunction(queryCost: 13)
        );
ketanp
Visitor
3 0 0

Great