Call API Resolve a payment when create payment apps

adiputra22
Shopify Partner
7 0 1

Hi Shopify Team And Community,

I on developing payment app and now i try to call api Resolve A Payment like at this documentation below:

https://shopify.dev/apps/payments/processing-a-payment#resolve-a-payment

But when i call it with PHP Http Guzzle. Response from API quite strange like this image

 

Screenshot_594.png

 

This is code that i create under PHP:

<?php

namespace App\Services\Shopify\Api\Payment;

use App\Services\Shopify\Api\ApiService;
use GuzzleHttp\Client;
use Illuminate\Support\Facades\Log;

class PaymentSessionResolveApi extends ApiService
{
    protected $id = "";
    protected $authorizationExpiresAt = "";

    public function setId($id)
    {
        $this->id = $id;
    }

    public function setAuthorizationExpiresAt($authorizationExpiresAt)
    {
        $this->authorizationExpiresAt = $authorizationExpiresAt;
    }

    public function handle()
    {
        $params = [
            'query' => $this->getQueryString(),
            'variables' => [
                'id' => $this->id,
                'authorizationExpiresAt' => $this->authorizationExpiresAt
            ]
        ];

        try {
            $client = new Client();

            return $client->post($this->getUrl(), [
                'body' => json_encode($params),
                'headers' => [
                    'Accept' => 'application/json',
                    'Content-Type' => 'application/graphql',
                    'X-Shopify-Access-Token' => $this->getToken()
                ],
                'verify' => false
            ]);
        } catch (\Exception $e) {
            Log::error($e);
        }
    }

    private function getQueryString()
    {
        $queryString = <<<'GRAPHQL'
{
    mutation PaymentSessionResolve($id: ID!, $authorizationExpiresAt: DateTime) {
      paymentSessionResolve(id: $id, authorizationExpiresAt: $authorizationExpiresAt) {
        paymentSession {
          id
          status {
            code
          }
          nextAction {
            action
            context {
              ... on PaymentSessionActionsRedirect {
                redirectUrl
              }
            }
          }
        }
        userErrors {
          field
          message
        }
      }
    }
}
GRAPHQL;

        return $queryString;
    }
}

 

Anyone can help me please for this api. Did i missing some step or passing data?
The toke of shop and domain of shop already set but the result of response still dont readable for me.

Thank you for your helping.

Reply 1 (1)
bhavinshah
Shopify Partner
3 0 0

Hi @adiputra22 
Could you tell me what you are passing for authorizationExpiresAt because when I am trying to resolve the payment I am getting this response

(
    [data] => Array
        (
            [paymentSessionResolve] => Array
                (
                    [paymentSession] => 
                    [userErrors] => Array
                        (
                            [0] => Array
                                (
                                    [field] => Array
                                        (
                                            [0] => id
                                        )

                                    [message] => Argument 'authorization_expires_at' was given, but payment session kind is not authorization.
                                )

                        )

                )

        )

    [extensions] => Array
        (
            [cost] => Array
                (
                    [requestedQueryCost] => 13
                    [actualQueryCost] => 10
                    [throttleStatus] => Array
                        (
                            [maximumAvailable] => 54600
                            [currentlyAvailable] => 54590
                            [restoreRate] => 2730
                        )

                )

        )

)

 What exactly will be the value for $authorizationExpiresAt??
Thanks!