PHP code example of advancelearn / manage-payment-and-orders

1. Go to this page and download the library: Download advancelearn/manage-payment-and-orders library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

advancelearn / manage-payment-and-orders example snippets


 \Advancelearn\ManagePaymentAndOrders\ManagePayOrderServiceProvider::class,

php artisan vendor:publish

  Tag: AdvanceLearnManagePayAndOrder-migrations ...............
 
php artisan migrate

php artisan vendor:publish

Tag: AdvanceLearnManagePayAndOrder-seeds .....

$items = [
    0 => [
        'quantity' => 2,
        "inventory_id" => 1
    ]

];
$shippingId = $request->shippingId; //It can be null
$addressId = (int)$request->addressId;
$newOrder = app('orderFunction')->store($shippingId, $addressId, "test from create new order", $items);
//
return $newOrder;
#params :
# shippingId => Type of shipment,
# $addressId => The address ID stored for the user in the address table ,
# $description => create new order by user example .... ,
# $items =>  Enter the product order number and inventory ID for the corresponding model


    public function inventories()
    {
        return $this->morphMany(app('inventory'), 'adm_inventories');
    }


use Advancelearn\ManagePaymentAndOrders\PaymentConfirmationInterface;

class Product extends Model implements PaymentConfirmationInterface
{
    //you're methods or logic
    
    //added this method after implemention:
    public function paymentConfirmation($user_id, $inventory_id, $quantity)
    {
        //you're added logic after paymentConfirmation
    }
}


use Advancelearn\ManagePaymentAndOrders\Enums\AuditTypes; 

$order = app('order')::findOrFail($orderId);

if ($order->audits->where('id', AuditTypes::PAID)->count()) {
    return response()->json(['errors' => 'Already paid'], 422);
}
    

$invoice = new Invoice;

$invoice->amount($order->payment_price);

 app('payment')::create
 ([
    'order_id' => $order->id,
    'driver' => $request->input('driver'),
    'transaction_id' => //transactionId from your gateway sent request for pay,
    'amount' => $order->payment_price
]);

public function paymentConfirmation(Request $request)
{
    $payment = app('payment')::where('transaction_id', $transactionId)->first();
    $order = app('order')::find($payment->order_id);
     $receipt = //api call gateway for verifyPayment and get response add to this variable
    $this->verifyPayAndConfirm($payment, $order, $request);
//          return redirect('https://example.com?gatewayOrderID=' .
//           $paymentTransaction->OrderId ?? null . '&RRN=' .
//           $paymentTransaction->RRN ?? null);
}

use Advancelearn\ManagePaymentAndOrders\Enums\AuditTypes; 

private function verifyPayAndConfirm($receipt, $payment, Request $request): void
{
    $payment->reference_id = $receipt->getReferenceId();
    $payment->transaction = $request->all();
    $payment->driver = $receipt->getDriver();
    $payment->save();
    $order->audits()->attach([AuditTypes::PAID => ['description' => 'Payment was successful']]);
    foreach ($order->items as $item) {
        //this method called fromAnd finally, this
        // method reaches the method that we implemented
        // in the corresponding model of the interface 
        $item->PaymentConfirmation($order->address->user_id);
    }
    return $receipt;
}

$paginateCount = 6;
app('orderFunction')->getOrders($paginateCount);

app('orderFunction')->show($order);

$shippingId = app('shipping')::find(1)->pluck('id')->first();

$items = [
    0 => [
        'quantity' => 1,
        "inventory_id" => 1,
        "price" => 168000//It can be Nal
    ]
];
$shippingId = $request->shippingId; //can be null
$addressId = $request->addressId;
$auditId = app('audit')::find(2)->toArray();
$orderId = 9;
$update = app('orderFunction')->update($shippingId, $addressId, "update order for test", "2023-09-28 10:01:03", $items, $auditId['id'], $orderId);
#params => shippingId , $addressId , $description , $shippingDate , $items , $auditID , $orderId

$delete =  app('orderFunction')->destroyByUser($orderId);
return $delete;

$delete =  app('orderFunction')->destroyByAdmin($orderId);
return $delete;

return app('orderFunction')->getOrders(); // get Order List for AdminPanel
return app('orderFunction')->singleOrder(5); // get singleOrder for AdminPanel

return app('orderFunction')->ordersOfTheLoggedInUser(); // get user Authenticated Order list
return app('orderFunction')->SingleOrderOfTheLoggedInUser(5); //get user Authenticated singleOrder

return app('paymentFunction')->getPayments(); // get PaymentList for AdminPanel

return app('paymentFunction')->singlePayment(1); //get singlePayment for AdminPanel


return app('paymentFunction')->paymentsOfTheLoggedInUser(); //get user Authenticated payment list

return app('paymentFunction')->SinglePaymentsOfTheLoggedInUser(1); //send $paymentId