PHP code example of ahmedebead / cakephp-4-paymob

1. Go to this page and download the library: Download ahmedebead/cakephp-4-paymob 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/ */

    

ahmedebead / cakephp-4-paymob example snippets


// src/Application.php

public function bootstrap()
{
    $this->addPlugin('CakephpLte', ['autoload' => true, 'bootstrap' => true, 'routes' => true]);
}

   $ bin/cake plugin load CakeRestApi

// new config/cakephplte.php file

return [
    'CakephpPaymob' => [
        'apiKey' => '{your-api-key-here-from-your-account}',
        'card_integration_id' => 'card_integration_id', //https://accept.paymob.com/portal2/en/PaymentIntegrations
        'mobile_wallet_integration_id' => 'mobile_wallet_integration_id', //https://accept.paymob.com/portal2/en/PaymentIntegrations

    ]
];

// config/bootstrap.php

Configure::load('cakephppaymob', 'default');

use CakephpPaymob\CakephpPaymob;


 $client = new CakephpPaymob();



$orderData = [
   "delivery_needed" => "false",  // Required -- Set it to be true if your order needs to be delivered by Accept's product delivery services.
   "amount_cents" => 100, // price * 100  Required
   "currency" => "EGP", // Required
   "merchant_order_id" => 5, 
   "items" => [// Required
         [
            "name" => "ASC1515", 
            "amount_cents" => "500000", 
            "description" => "Smart Watch", 
            "quantity" => "1" 
         ], 
         [
               "name" => "ERT6565", 
               "amount_cents" => "200000", 
               "description" => "Power Bank", 
               "quantity" => "1" 
            ] 
      ], 

]; 

 $order = $client->OrderRegistrationAPI($orderData);




use CakephpPaymob\PaymentTypes\Card;

 $card = new Card();
        $PaymentKey =  $card->PaymentKeyRequest([
            'amount_cents' => 150 * 100, //put your price
            'currency' => 'EGP',
            'order_id' => $order['id'],// From step 3 before
            "billing_data" => [ // put your client information
                "apartment" => "803",
                "email" => "[email protected]",
                "floor" => "42",
                "first_name" => "Clifford",
                "street" => "Ethan Land",
                "building" => "8028",
                "phone_number" => "+86(8)9135210487",
                "shipping_method" => "PKG",
                "postal_code" => "01898",
                "city" => "Jaskolskiburgh",
                "country" => "CR",
                "last_name" => "Nicolas",
                "state" => "Utah"
            ]
        ]);

        $this->set('PaymentKey',$PaymentKey);