Below is an example code for "Paytrail_Module_Rest.php", a set of classes for interacting with a rest api for a payment gateway. Some of the classes can be instantiated ahead of time such as (Paytrail_Module_rest which holds credentials), but some need to be instantiated with information only available in the controller, (such as Paytrail_Module_Rest_Payment_S1 which sets payment details such as price)
Can anyone suggest a clean way of injecting it into slim3? I can't see any good way of doing it with the standard container injection methods.
$urlset = new\App\Service\Paytrail\Paytrail_Module_Rest_Urlset(
"https://www.demoshop.com/sv/success", // return address for successful payment
"https://www.demoshop.com/sv/failure", // return address for failed payment
"https://www.demoshop.com/sv/notify", // address for payment confirmation from Paytrail server
"" // pending url not in use
);
$orderNumber = '1';
$price = 99.00;
$payment = new \App\Service\Paytrail\Paytrail_Module_Rest_Payment_S1($orderNumber, $urlset, $price);
$payment->setLocale('en_US');
$module = new \App\Service\Paytrail\Paytrail_Module_Rest(13466, '6pKF4jkv97zmqBJ3ZL8gUw5DfT2NMQ');
try {
$result = $module->processPayment($payment);
}
catch (\App\Service\Paytrail\Paytrail_Exception $e) {
die('Error in creating payment to Paytrail service:'. $e->getMessage());
}
echo $result->getUrl();
( credentials listed here are public test credentials )