Call API Resolve a payment when create payment apps

adiputra22
New Member
1 0 0

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.

Replies 0 (0)