Else yazan kısmın devamı var orayı ele almadım ondan orası eksik gibi createPayment metodunu çağırıyorum orada iyzico dan ödeme alınma işlemleri vb şeyler yapıldıktan sonra o metodun içinde success kısmını yakalıyorum sonra metoda yönlendirdiğim yerden kod devam edeceğin de payment['type'] yazan yere geldiğin de orada getStatus() kısmını tekrar alamıyorum array hatası dönüyor fakat failure dönerse getStatus durumunu alabiliyorum hata vermiyor bu noktayı nasıl aşabilirim tam olarak acaba ?
else {
$payment = $this->createPayment($request, $paymentID);
if ($payment['type'] == 'url') {
return response()->json($payment);
} else {
return response()->json(flash(['message' => $payment['message'], 'status' => 'error']), 422);
}
if ($payment->getStatus() == 'failure') {
$errorMessage = $payment->getErrorMessage();
return response()->json(flash(['message' => $errorMessage, 'status' => 'error']), 422);
} else {
return $payment->getHtmlContent();
}
}
}
public function createPayment($request, $paymentID)
{
$paymentData = Payment::find($paymentID);
$cardExpiry = explode('/', $request->expireDate);
$cardName=$request->name;
$cvc=$request->cvc;
$IpAddress=$request->ip();
$cardNumber = preg_replace('/\s+/', '', $request->cardNumber);
$month = preg_replace('/\s+/', '', $cardExpiry[0]);
$year = preg_replace('/\s+/', '', $cardExpiry[1]);
$firstAddress = Auth::user()->addresses->first();
$options = new \Iyzipay\Options();
$options->setApiKey(env('IYZIPAY_API_KEY'));
$options->setSecretKey(env('IYZIPAY_SECRET_KEY'));
$options->setBaseUrl(env('IYZIPAY_BASE_URL'));
$request = new \Iyzipay\Request\CreatePaymentRequest();
$request->setLocale(\Iyzipay\Model\Locale::TR);
$request->setConversationId("12345655789");
$request->setPrice("106.2");
$request->setPaidPrice("106.2");
$request->setCurrency(\Iyzipay\Model\Currency::TL);
$request->setInstallment(1);
$request->setBasketId("B67432");
$request->setPaymentChannel(\Iyzipay\Model\PaymentChannel::WEB);
$request->setPaymentGroup(\Iyzipay\Model\PaymentGroup::PRODUCT);
$paymentCard = new \Iyzipay\Model\PaymentCard();
$paymentCard->setCardHolderName($cardName);
$paymentCard->setCardNumber($cardNumber);
$paymentCard->setExpireMonth($month);
$paymentCard->setExpireYear($year);
$paymentCard->setCvc($cvc);
$paymentCard->setRegisterCard(0);
$request->setPaymentCard($paymentCard);
$buyer = new \Iyzipay\Model\Buyer();
$buyer->setId("BY789");
$buyer->setName(Auth::user()->first_name);
$buyer->setSurname(Auth::user()->last_name);
$buyer->setEmail(Auth::user()->email);
$buyer->setIdentityNumber($firstAddress->tax_number);
$buyer->setRegistrationAddress($firstAddress->address);
$buyer->setIp($IpAddress);
$buyer->setCity("Istanbul");
$buyer->setCountry("Turkey");
$request->setBuyer($buyer);
$billingAddress = new \Iyzipay\Model\Address();
$billingAddress->setContactName(Auth::user()->full_name);
$billingAddress->setCity("Ankara");
$billingAddress->setCountry("Turkey");
$billingAddress->setAddress($firstAddress->address);
$request->setBillingAddress($billingAddress);
$basketItems = array();
$firstBasketItem = new \Iyzipay\Model\BasketItem();
$firstBasketItem->setId("BI101");
$firstBasketItem->setName("Deneme Ürün");
$firstBasketItem->setCategory1("Collectibles");
$firstBasketItem->setCategory2("Accessories");
$firstBasketItem->setItemType(\Iyzipay\Model\BasketItemType::VIRTUAL);
$firstBasketItem->setPrice("106.2");
$basketItems[0] = $firstBasketItem;
$request->setBasketItems($basketItems);
$payment = \Iyzipay\Model\Payment::create($request, $options);
if ($payment->getStatus() === 'success') {
// Payment was successful
return [
'type' => 'url',
'message' => 'Success',
];
} else {
// Payment was not successful
$error = $payment->getErrorMessage();
return [
'type' => 'failure',
'message' => $error,
];
}