Donation system of OYD
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
bagis/app/Http/Controllers/DonationController.php

111 lines
4.4 KiB

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class DonationController extends Controller
{
public function index()
{
return view('donate');
}
public function donate(Request $request)
{
// dd($request);
$request->validate([
"amount" => 'required|numeric',
"currency" => 'required|in:USD,EUR,TL',
"frequency" => 'required|in:once,monthly,annually',
"card_holder_name" => 'required|string|max:100',
"card_number" => 'required|digits_between:15,16',
"card_expire_month" => 'required|digits:2',
"card_expire_year" => 'required|digits:2',
"card_cvc" => 'required|digits_between:3,4',
"first_name" => 'required|string',
"last_name" => 'required|string',
"show_name" => 'nullable|boolean',
"email" => 'required|email',
"billing_contact_name" => 'required|string',
"billing_address" => 'required|string',
"billing_city" => 'required|string',
"billing_country" => 'required|string',
"billing_zipcode" => 'nullable|string',
]);
$iyzipayCurrencies = [
"USD" => \Iyzipay\Model\Currency::USD,
"EUR" => \Iyzipay\Model\Currency::EUR,
"TL" => \Iyzipay\Model\Currency::TL,
];
$options = new \Iyzipay\Options();
$options->setBaseUrl(config("services.iyzipay.base_url"));
$options->setApiKey(config("services.iyzipay.api_key"));
$options->setSecretKey(config("services.iyzipay.secret_key"));
$paymentRequest = new \Iyzipay\Request\CreatePaymentRequest();
$paymentRequest->setLocale(\Iyzipay\Model\Locale::EN);
$paymentRequest->setConversationId(\Str::random(6));
$paymentRequest->setPrice($request->amount);
$paymentRequest->setPaidPrice($request->amount);
$paymentRequest->setCurrency($iyzipayCurrencies[$request->currency]);
$paymentRequest->setInstallment(1);
$paymentRequest->setPaymentChannel(\Iyzipay\Model\PaymentChannel::WEB);
$paymentRequest->setPaymentGroup(\Iyzipay\Model\PaymentGroup::SUBSCRIPTION);
$paymentCard = new \Iyzipay\Model\PaymentCard();
$paymentCard->setCardHolderName($request->card_holder_name);
$paymentCard->setCardNumber($request->card_number);
$paymentCard->setExpireMonth($request->card_expire_month);
$paymentCard->setExpireYear("20" . $request->card_expire_year);
$paymentCard->setCvc($request->card_cvc);
if ($request->frequency !== "once") {
$paymentCard->setRegisterCard(1);
}
$paymentRequest->setPaymentCard($paymentCard);
$buyer = new \Iyzipay\Model\Buyer();
$buyer->setId(md5($request->email));
$buyer->setName($request->first_name);
$buyer->setSurname($request->last_name);
$buyer->setEmail($request->email);
$buyer->setIdentityNumber("11111111111");
$buyer->setRegistrationAddress($request->billing_address);
$buyer->setIp($request->ip());
$buyer->setCity($request->billing_city);
$buyer->setCountry($request->billing_country);
if ($request->billing_zipcode) {
$buyer->setZipCode($request->billing_zipcode);
}
$paymentRequest->setBuyer($buyer);
$billingAddress = new \Iyzipay\Model\Address();
$billingAddress->setContactName($request->billing_contact_name);
$billingAddress->setAddress($request->billing_address);
$billingAddress->setCity($request->billing_city);
$billingAddress->setCountry($request->billing_country);
if ($request->billing_zipcode) {
$billingAddress->setZipCode($request->billing_zipcode);
}
$paymentRequest->setBillingAddress($billingAddress);
$basketItems = array();
$basketItem = new \Iyzipay\Model\BasketItem();
$basketItem->setId("donation-" . $request->frequency);
$basketItem->setName("Donation - " . $request->frequency);
$basketItem->setCategory1("Donation");
$basketItem->setCategory2($request->frequency);
$basketItem->setItemType(\Iyzipay\Model\BasketItemType::VIRTUAL);
$basketItem->setPrice($request->amount);
$basketItems[] = $basketItem;
$paymentRequest->setBasketItems($basketItems);
$payment = \Iyzipay\Model\Payment::create($paymentRequest, $options);
dd($payment);
}
}