首页 > 解决方案 > laravel 8中的iyzico付款方式失败

问题描述

我已经通过 Composer 安装了 Iyzico 付款方式,并按照文档中的每个步骤进行操作,但我正在尝试加载 Iyzico 付款的默认形式,但是当我重新加载页面时,它显示失败状态只是显示

奥德梅赛法

和失败所以我该怎么做

这是我在控制器中的代码

public function payment()
    {
        $iyzico = new Iyzico();
        $payment = $iyzico->setForm([
            'conversationID' => '123456789',
            'price' => '120.0',
        ])
            ->paymentForm();

        $paymentContent = $payment->getCheckoutFormContent();
        $paymentStatus = $payment->getStatus();
        return view(
            'iyzico',
            compact('paymentContent', 'paymentStatus')
        );
    }

这是 iyzico 类代码

<?php

namespace App\Libraries;

use PhpParser\Node\Expr\Cast\Array_;

class Iyzico 
{
    protected $options;
    protected $request;
    protected $basketItems;
    public function __construct()
    {
        $this->options = new \Iyzipay\Options();
        $this->options->setApiKey("your api key");
        $this->options->setSecretKey("your secret key");
        $this->options->setBaseUrl("https://sandbox-api.iyzipay.com");
        $this->basketItems = [];
    }

    public function setForm(array $params)
    {
        $this->request = new \Iyzipay\Request\CreateCheckoutFormInitializeRequest();
        $this->request->setLocale(\Iyzipay\Model\Locale::TR);
        $this->request->setConversationId($params['conversationID']);
        $this->request->setPrice($params['price']);
 
        return $this;
    }

    public function setBuyer(array $params)
    {
        $buyer = new \Iyzipay\Model\Buyer();
        $buyer->setId($params['id']);
        $buyer->setName($params['name']);
        return $this;
    }

    public function setShipping(array $params)
    {
        $shippingAddress = new \Iyzipay\Model\Address();
        $shippingAddress->setContactName($params['name']);
        $this->request->setShippingAddress($shippingAddress);
        return $this;
    }

    public function setBilling(array $params)
    {
        $billingAddress = new \Iyzipay\Model\Address();
        $billingAddress->setContactName($params['name']);
 
        $this->request->setBillingAddress($billingAddress);
        return $this;
    }

    public function setItem(array $items)
    {
        foreach ($items as $key => $value) {
            $basketItem = new \Iyzipay\Model\BasketItem();
            $basketItem->setId($value['id']);
            $basketItem->setName($value['name']);
           
            array_push($this->basketItems, $basketItem);
        }
        $this->request->setBasketItems($this->basketItems);
        return $this;
    }

    public function paymentForm()
    {
        $form = \Iyzipay\Model\CheckoutFormInitialize::create($this->request, $this->options);
        return $form;
    }
}

这是我的 iyzico.blade.php 页面

   <article>
        <h1>odeme sayfa</h1>
        <div>
            {{ $paymentContent }}
            {{ $paymentStatus }}
            <div id="iyzipay-checkout-form" class="responsive"></div>
        </div>
    </article>

标签: phplaravel

解决方案


推荐阅读