If payer wants to fund payments using KROOZ PAY, set payment method to KROOZ PAY Wallet or KROOZ PAY Gateway.
Specify the payment amount and the currency.
It’s a Transaction resource where the amount object has to be set.
Set the urls where buyer should redirect after transaction is completed or cancelled.
It’s a payment resource where all Payer, Amount, RedirectUrls and Credentials of merchant (Client ID and Client Secret) has to be set. Then after initialized into payment object, need to call create method. It will generate a redirect URL. Users have to redirect into this URL to complete the transaction.
require 'vendor/autoload.php'; //if you want to change the namespace/path from 'KroozPay' - lines[1-5] - to your desired name, i.e. (use KroozPay\Api\Amount; to use MyDomain\Api\Amount;), then you must change the folders name that holds the API classes as well as change the property 'KroozPay' in (autoload->psr-0) of (php-sdk/composer.json) file to your desired name and run "composer dump-autoload" command from sdk root use KroozPay\Api\Payer; use KroozPay\Api\Amount; use KroozPay\Api\Transaction; use KroozPay\Api\RedirectUrls; use KroozPay\Api\Payment; //Payer Object $payer = new Payer(); $payer->setPaymentMethod('KroozPay'); //preferably, your system name, example - KROOZ PAY //Amount Object $amountIns = new Amount(); $amountIns->setTotal(20)->setCurrency('USD'); //must give a valid currency code, code must exist in merchant wallet //Transaction Object $trans = new Transaction(); $trans->setAmount($amountIns); //RedirectUrls Object $urls = new RedirectUrls(); $urls->setSuccessUrl('http://your-merchant-domain.com/example-success.php') //success url - the merchant domain page, to redirect after successful payment, see sample example-success.php file in sdk root, example - https://kroozpay.com/gateway/example-success.php ->setCancelUrl('http://your-merchant-domain.com/'); //cancel url - the merchant domain page, to redirect after cancellation of payment, example - https://kroozpay.com/gateway //Payment Object $payment = new Payment(); $payment->setCredentials([ //client id & client secret, see merchants->setting(gear icon) 'client_id' => 'place your client id here', //must provide correct client id of an express merchant 'client_secret' => 'place your client secret here' //must provide correct client secret of an express merchant ])->setRedirectUrls($urls) ->setPayer($payer) ->setTransaction($trans); try { $payment->create(); //create payment header("Location: ".$payment->getApprovedUrl()); //checkout url } catch (Exception $ex) { print $ex; exit; }
composer clear-cache
composer install
composer dump-autoload