Payment external classes / php code


#1

Using Slim 3.0 I have developed a platform which need payment integration. The payment provider si supplying php code for a simple integration. Is it any solution to use “external code/class” with Slim?

See below the payment provider php code:

require_once ‘Mobilpay/Payment/Request/Abstract.php’;
require_once ‘Mobilpay/Payment/Request/Card.php’;
require_once ‘Mobilpay/Payment/Invoice.php’;
require_once ‘Mobilpay/Payment/Address.php’;

#for testing purposes, all payment requests will be sent to the sandbox server. Once your account will be active you must switch back to the live server https://secure.mobilpay.ro
#in order to display the payment form in a different language, simply add the language identifier to the end of the paymentUrl, i.e https://secure.mobilpay.ro/en for English
$paymentUrl = ‘http://sandboxsecure.mobilpay.ro’;
//$paymentUrl = ‘https://secure.mobilpay.ro’;
// this is the path on your server to the public certificate. You may download this from Admin -> Conturi de comerciant -> Detalii -> Setari securitate
$x509FilePath = ‘i.e: /home/certificates/public.cer’;
try
{
srand((double) microtime() * 1000000);
$objPmReqCard = new Mobilpay_Payment_Request_Card();
#merchant account signature - generated by mobilpay.ro for every merchant account
#semnatura contului de comerciant - mergi pe www.mobilpay.ro Admin -> Conturi de comerciant -> Detalii -> Setari securitate
$objPmReqCard->signature = ‘XXXX-XXXX-XXXX-XXXX-XXXX’;
#you should assign here the transaction ID registered by your application for this commercial operation
#order_id should be unique for a merchant account
$objPmReqCard->orderId = md5(uniqid(rand()));
#below is where mobilPay will send the payment result. This URL will always be called first; mandatory
$objPmReqCard->confirmUrl = ‘http://your.confirm.url’;
#below is where mobilPay redirects the client once the payment process is finished. Not to be mistaken for a “successURL” nor “cancelURL”; mandatory
$objPmReqCard->returnUrl = ‘http://your.return.url’;

#detalii cu privire la plata: moneda, suma, descrierea
#payment details: currency, amount, description
$objPmReqCard->invoice = new Mobilpay_Payment_Invoice();
#payment currency in ISO Code format; permitted values are RON, EUR, USD, MDL; please note that unless you have mobilPay permission to 
#process a currency different from RON, a currency exchange will occur from your currency to RON, using the official BNR exchange rate from that moment
#and the customer will be presented with the payment amount in a dual currency in the payment page, i.e N.NN RON (e.ee EUR)
$objPmReqCard->invoice->currency	= 'RON';
$objPmReqCard->invoice->amount		= '1.00';
#available installments number; if this parameter is present, only its value(s) will be available
//$objPmReqCard->invoice->installments= '2,3';
#selected installments number; its value should be within the available installments defined above
//$objPmReqCard->invoice->selectedInstallments= '3';
    //platile ulterioare vor contine in request si informatiile despre token. Prima plata nu va contine linia de mai jos.
    $objPmReqCard->invoice->tokenId = 'token_id';
$objPmReqCard->invoice->details		= 'Plata cu card-ul prin mobilPay';

#detalii cu privire la adresa posesorului cardului
#details on the cardholder address (optional)
$billingAddress 				= new Mobilpay_Payment_Address();
$billingAddress->type			= $_POST['billing_type']; //should be "person"
$billingAddress->firstName		= $_POST['billing_first_name'];
$billingAddress->lastName		= $_POST['billing_last_name'];
$billingAddress->address		= $_POST['billing_address'];
$billingAddress->email			= $_POST['billing_email'];
$billingAddress->mobilePhone		= $_POST['billing_mobile_phone'];
$objPmReqCard->invoice->setBillingAddress($billingAddress);

#detalii cu privire la adresa de livrare
#details on the shipping address
$shippingAddress 				= new Mobilpay_Payment_Address();
$shippingAddress->type			= $_POST['shipping_type'];
$shippingAddress->firstName		= $_POST['shipping_first_name'];
$shippingAddress->lastName		= $_POST['shipping_last_name'];
$shippingAddress->address		= $_POST['shipping_address'];
$shippingAddress->email			= $_POST['shipping_email'];
$shippingAddress->mobilePhone		= $_POST['shipping_mobile_phone'];
$objPmReqCard->invoice->setShippingAddress($shippingAddress);

#uncomment the line below in order to see the content of the request
//echo "<pre>";print_r($objPmReqCard);echo "</pre>";
$objPmReqCard->encrypt($x509FilePath);

}
catch(Exception $e)
{
}

Tank you in advance for all suggestions!


#2

The above code is where I got the error: Class ‘App\Controllers\Mobilpay_Payment_Request_Card’ not found


#3

Try adding a forward slash to ensure the class is looked up in the default namespace:

$objPmReqCard = new \Mobilpay_Payment_Request_Card();  // note the \ before Mobilpay_Pay...