Viewing file: IyzicoPayment.php (6.34 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
namespace Modules\PaymentGateway\TopUpProvider;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Log;
use Modules\PaymentGateway\Services\PaymentCredentials;
class IyzicoPayment implements PaymentInterface
{
public $paymentId;
public $request;
public $number;
public $redirect_url;
public $error_message;
public $return_view;
public $will_redirect = false;
public function __construct()
{
}
public function pay()
{
// TODO: Implement pay() method.
}
public function number_request($numberReq)
{
$this->numberReq = $numberReq;
return $this;
}
public function topUpRequest($topup_request){
$this->topup_request=$topup_request;
return $this;
}
public function request($request)
{
$this->paymentId = $request->paymentId;
$this->request = $request;
return $this;
}
public function amount($amount)
{
$this->amount = $amount;
return $this;
}
public function getCredentials()
{
$credentials= PaymentCredentials::get();
if (!isset($credentials) || (!$credentials->iyzico_api_key || !$credentials->iyzico_secret_key)) {
throw new \Exception('Credentials not found. Please contact with the administrator');
}
return $credentials;
}
public function will_redirect()
{
// TODO: Implement will_redirect() method.
return $this->will_redirect;
}
public function redirect_url()
{
// TODO: Implement redirect_url() method.
return $this->redirect_url;
}
public function return_view()
{
// TODO: Implement redirect_url() method.
return $this->return_view;
}
public function error_message()
{
// TODO: Implement error_message() method.
return $this->error_message;
}
public function process()
{
try {
$requestData=$this->request;
$number = $this->number;
$credentials = $this->getCredentials();
$user = auth('customer')->user();
$setCardNumber = ('0123456789') . '' . $user->id;
$options = new \Iyzipay\Options();
$options->setApiKey("$credentials->iyzico_api_key");
$options->setSecretKey("$credentials->iyzico_secret_key");
$options->setBaseUrl("https://sandbox-api.iyzipay.com");
$request = new \Iyzipay\Request\CreatePaymentRequest();
$request->setLocale(\Iyzipay\Model\Locale::TR);
$request->setConversationId("123456789");
$request->setPrice("$number->sell_price");
$request->setPaidPrice("$this->amount");
$request->setCurrency(\Iyzipay\Model\Currency::TL);
$request->setInstallment(1);
$request->setBasketId("$this->amount");
$request->setPaymentChannel(\Iyzipay\Model\PaymentChannel::WEB);
$request->setPaymentGroup(\Iyzipay\Model\PaymentGroup::PRODUCT);
$paymentCard = new \Iyzipay\Model\PaymentCard();
$paymentCard->setCardHolderName("$requestData->iyzico_card_holder_name");
$paymentCard->setCardNumber("$requestData->iyzico_card_number");
$paymentCard->setExpireMonth("$requestData->iyzico_card_expired_date");
$paymentCard->setExpireYear("$requestData->iyzico_card_expired_year");
$paymentCard->setCvc("$requestData->iyzico_card_cvc");
$paymentCard->setRegisterCard(0);
$request->setPaymentCard($paymentCard);
$buyer = new \Iyzipay\Model\Buyer();
$buyer->setId("ID-.''.$user->ID");
$buyer->setName("$user->first_name");
$buyer->setSurname("$user->last_name");
$buyer->setGsmNumber("+905350000000");
$buyer->setEmail("$user->email");
$buyer->setIdentityNumber("74300864791");
$buyer->setLastLoginDate(Carbon::now());
$buyer->setRegistrationDate(Carbon::now());
$buyer->setRegistrationAddress("Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1");
$buyer->setIp("85.34.78.112");
$buyer->setCity("null");
$buyer->setCountry("null");
$buyer->setZipCode("0000");
$request->setBuyer($buyer);
$shippingAddress = new \Iyzipay\Model\Address();
$shippingAddress->setContactName("Jane Doe");
$shippingAddress->setCity("Istanbul");
$shippingAddress->setCountry("Turkey");
$shippingAddress->setAddress("Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1");
$shippingAddress->setZipCode("34742");
$request->setShippingAddress($shippingAddress);
$billingAddress = new \Iyzipay\Model\Address();
$billingAddress->setContactName("Jane Doe");
$billingAddress->setCity("Istanbul");
$billingAddress->setCountry("Turkey");
$billingAddress->setAddress("Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1");
$billingAddress->setZipCode("34742");
$request->setBillingAddress($billingAddress);
$basketItems = array();
$numberId= 'USER-number-'.$user->id;
$firstBasketItem = new \Iyzipay\Model\BasketItem();
$firstBasketItem->setId("$numberId");
$firstBasketItem->setName("Binocular");
$firstBasketItem->setCategory1("Collectibles");
$firstBasketItem->setCategory2("Accessories");
$firstBasketItem->setItemType(\Iyzipay\Model\BasketItemType::PHYSICAL);
$firstBasketItem->setPrice("$number->sell_price");
$basketItems[0] = $firstBasketItem;
$request->setBasketItems($basketItems);
$payment = \Iyzipay\Model\Payment::create($request, $options);
// dd($payment);
if ($payment->getStatus()=='failure' || $payment->getStatus()=='failure'){
$this->error_message= $payment->getErrorMessage();
throw new \Exception($payment->getErrorMessage());
}
} catch (\Exception $ex) {
Log::error($ex);
$this->error_message= $ex->getMessage();
}
}
}
|