You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel集成Iyzico支付时出现Invalid signature错误求助

搭建Laravel电商系统集成Iyzico支付时遇到Invalid signature错误求助

我正在使用Laravel搭建电商系统并集成Iyzico支付,但遇到了Invalid signature错误,尝试多种方法仍无法解决,不确定是否是代码问题,希望能得到帮助。

错误截图

错误截图

相关代码

路径:app\Repositories\AppointmentRepository.php

/**
 * Store a newly created resource in storage.
 */
public function store(AppointmentRequest $req): JsonResponse
{
    // dd($request->validated());

    try {
        $user = User::find(auth()->user()->id);
        $user = new UserResource($user);

        $data = $req->validated();
        $data['user_id'] =  $user->id;
        $data['conversation_id'] = $req->psychologist_id;
        $data['basket_id'] = 'OT#BASID' . Str::random(10);
        $data['buyer_id'] = $user->id;
        $data['registration_date'] = now();
        $data['card_save'] = $req->card_save ? 1 : 0;
        $data['invoice_full_name'] = $data['invoice_name'] . ' ' . $data['invoice_surname'];
        $data['ip_address'] = $req->ip();

        // Iyzico Payment Transactions
        $payment = $this->iyzicoPayment($data, $user);

       // dd($payment);

        if (isset($payment)) {
            return response()->json([
                'status' => [
                    'code' => Response::HTTP_CREATED,
                    'message' => 'Your appointment was successfully created.',
                ],
                'payment' => $payment,
            ], Response::HTTP_CREATED);
        }
    } catch (\Exception $e) {
        throw new ServerErrorException('appointment', $e);
    }
}

public function iyzicoPayment($data, $user): object
{
    $options = new \Iyzipay\Options();
    $options->setApiKey(config('services.iyzico.api_key'));
    $options->setSecretKey(config('services.iyzico.secret_key'));
    $options->setBaseUrl(config('services.iyzico.base_url'));

    $request = new \Iyzipay\Request\CreatePaymentRequest();
    $request->setLocale(\Iyzipay\Model\Locale::TR);
    // $request->setConversationId($data['conversation_id']);
    $request->setPrice("1");
    $request->setPaidPrice("1");
    $request->setCurrency(\Iyzipay\Model\Currency::TL);
    $request->setInstallment(1);
    $request->setBasketId($data['basket_id']);
    $request->setPaymentChannel(\Iyzipay\Model\PaymentChannel::WEB);
    $request->setPaymentGroup(\Iyzipay\Model\PaymentGroup::PRODUCT);

    $paymentCard = new \Iyzipay\Model\PaymentCard();
    $paymentCard->setCardHolderName($data['card_name']);
    $paymentCard->setCardNumber($data['card_number']);
    $paymentCard->setExpireMonth($data['card_month']);
    $paymentCard->setExpireYear($data['card_year']);
    $paymentCard->setCvc($data['card_cvv']);
    $paymentCard->setRegisterCard($data['card_save']);
    $request->setPaymentCard($paymentCard);

    $buyer = new \Iyzipay\Model\Buyer();
    $buyer->setId($data['buyer_id']);
    $buyer->setName($data['invoice_name']);
    $buyer->setSurname($data['invoice_surname']);
    $buyer->setGsmNumber($user->phone);
    $buyer->setEmail($user->email);
    $buyer->setIdentityNumber($user->identity_number);
    $buyer->setLastLoginDate($user->last_activity_at);
    $buyer->setRegistrationDate($data['registration_date']);
    $buyer->setRegistrationAddress($data['invoice_address']);
    $buyer->setIp($data['ip_address']);
    $buyer->setCity($data['invoice_city']);
    $buyer->setCountry("Turkey");
    $buyer->setZipCode($data['invoice_zipcode']);
    $request->setBuyer($buyer);

    $shippingAddress = new \Iyzipay\Model\Address();
    $shippingAddress->setContactName($data['invoice_full_name']);
    $shippingAddress->setCity($data['invoice_city']);
    $shippingAddress->setCountry("Turkey");
    $shippingAddress->setAddress($data['invoice_address']);
    $shippingAddress->setZipCode($data['invoice_zipcode']);
    $request->setShippingAddress($shippingAddress);

    $billingAddress = new \Iyzipay\Model\Address();
    $billingAddress->setContactName($data['invoice_full_name']);
    $billingAddress->setCity($data['invoice_city']);
    $billingAddress->setCountry("Turkey");
    $billingAddress->setAddress($data['invoice_address']);
    $billingAddress->setZipCode($data['invoice_zipcode']);
    $request->setBillingAddress($billingAddress);

    $basketItems = array();
    $firstBasketItem = new \Iyzipay\Model\BasketItem();
    $firstBasketItem->setId($data['basket_id']);
    $firstBasketItem->setName("OT Session");
    $firstBasketItem->setCategory1("Session Package");
    $firstBasketItem->setItemType(\Iyzipay\Model\BasketItemType::VIRTUAL);
    $firstBasketItem->setPrice($data['invoice_pricing']);
    $basketItems[0] = $firstBasketItem;
    $request->setBasketItems($basketItems);

    return \Iyzipay\Model\Payment::create($request, $options);
}

路径:app\Http\Controllers\Panel\AppointmentController.php

/**
 * Store a newly created resource in storage.
 */
public function store(AppointmentRequest $request): RedirectResponse
{
    $data = ConvertHelper::jsonToView($this->appointmentRepository->store($request));

    return redirect()->route('panel.appointments.for-client')->with(['status' => $data->status]);
}

我希望通过Iyzico完成支付并在交易成功后进入下一步。若我的实现方式有误,也可以提供Laravel 10.x版本的完整集成示例。

内容的提问来源于stack exchange,提问作者Erhan URGUN

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 22:27:02