The OpenPayU PHP library provides integration access to the PayU Gateway API ver. 1 and ver. 2
The following PHP extensions are required:
- cURL
- hash
- XMLWriter
- XMLReader
Full implementation guide [English] [Polish].
Quick guide [English] [Polish].
Add this line to your application's:
require_once 'lib/openpayu.php';
require_once realpath(dirname(__FILE__)) . '/../../config.php';
##Configure To configure OpenPayU environment you must provide a set of mandatory data:
OpenPayU_Configuration::setEnvironment('secure'); // production
OpenPayU_Configuration::setMerchantPosId('145227'); // POS
OpenPayU_Configuration::setClientSecret('12f071174cb7eb79d4aac5bc2f07563f'); //first MD5 key
OpenPayU_Configuration::setSignatureKey('13a980d4f851f3d9a1cfc792fb1f5e50'); //second MD5 key
OpenPayU_Configuration::setApiVersion(2);
OpenPayU_Configuration::setDataFormat('json'); // json, xml
##Usage
###Creating Hosted order
To create an order you must provide a Array with order data:
in your controller
$order['ContinueUrl'] = 'http://localhost/';
$order['NotifyUrl'] = 'http://localhost/';
$order['CustomerIp'] = '127.0.0.1';
$order['MerchantPosId'] = '45654';
$order['Description'] = 'New order';
$order['CurrencyCode'] = 'PLN';
$order['TotalAmount'] = 1000;
$order['ExtOrderId'] = '1342';
$order['ValidityTime'] = 48000;
$order['Products']['Product'][0]['Name'] = 'Product1';
$order['Products']['Product'][0]['UnitPrice'] = 1000;
$order['Products']['Product'][0]['Quantity'] = 1;
$order['PaymentMethods']['PaymentMethod'][0]['Type'] = 'PBL';
$order['Buyer']['Email'] = '[email protected]';
$order['Buyer']['Phone'] = '123123123';
$order['Buyer']['FirstName'] = 'Jan';
$order['Buyer']['LastName'] = 'Kowalski';
$order['Buyer']['Language'] = 'pl_PL';
$order['Buyer']['NIN'] = '123456';
$orderFormData = OpenPayU_Order::hostedOrderForm($order);
in your view
<html>
<?php echo $orderFormData; ?>
</html>
or just
echo $orderFormData
###Retrieving order from OpenPayU You can retrieve order by its PayU order_id
$response = OpenPayU_Order::retrieve('Z963D5JQR2230925GUEST000P01');
###Cancelling order You can cancel order by its PayU order_id
$response = OpenPayU_Order::cancel('Z963D5JQR2230925GUEST000P01');
###Updating order status
You can update order status to accept order when Autoreceive in POS is turned off
$status_update = array(
"OrderId" => 'Z963D5JQR2230925GUEST000P01',
"OrderStatus" => 'COMPLETED'
);
$response = OpenPayU_Order::status_update($status_update);
###Handling notifications from PayU
PayU sends requests to your application when order status changes
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$body = file_get_contents('php://input');
$data = stripslashes(trim($body));
$reponse = OpenPayU_Order::consumeNotification($data)
$response->Response->Status //NEW PENDING CANCELLED REJECTED COMPLETED WAITING_FOR_CONFIRMATION
$rsp = OpenPayU::buildOrderNotifyResponse($reponse->Response->Order->OrderId);
//you should response to PayU with special structure (OrderNotifyResponse)
header("Content-Type: application/json");
echo json_encode(OpenPayU_Util::parseXmlDocument(stripslashes($rsp)));
}
###Refund money
You can create refund to refund money on buyer account
$refund = OpenPayU_Refund::create(
'Z963D5JQR2230925GUEST000P01', //Order Id - required
'Money refund', //Description - required
'100' //Amount - If not provided, returns whole transaction, optional
);
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request