PHP code example of openpayu / openpayu_php_sdk
1. Go to this page and download the library: Download openpayu/openpayu_php_sdk 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/ */
openpayu / openpayu_php_sdk example snippets
{
""openpayu/openpayu" : "2.3.*"
}
}
composer.phar install
git clone https://github.com/PayU/openpayu_php.git
//set Production Environment
OpenPayU_Configuration::setEnvironment('secure');
//set POS ID and Second MD5 Key (from merchant admin panel)
OpenPayU_Configuration::setMerchantPosId('145227');
OpenPayU_Configuration::setSignatureKey('13a980d4f851f3d9a1cfc792fb1f5e50');
//set Oauth Client Id and Oauth Client Secret (from merchant admin panel)
OpenPayU_Configuration::setOauthClientId('145227');
OpenPayU_Configuration::setOauthClientSecret('12f071174cb7eb79d4aac5bc2f07563f');
//set Sandbox Environment
OpenPayU_Configuration::setEnvironment('sandbox');
//set POS ID and Second MD5 Key (from merchant admin panel)
OpenPayU_Configuration::setMerchantPosId('300046');
OpenPayU_Configuration::setSignatureKey('0c017495773278c50c7b35434017b2ca');
//set Oauth Client Id and Oauth Client Secret (from merchant admin panel)
OpenPayU_Configuration::setOauthClientId('300046');
OpenPayU_Configuration::setOauthClientSecret('c8d4b7ac61758704f38ed5564d8c0ae0');
OpenPayU_Configuration::setOauthGrantType('grant_type');
//set Oauth Client Id and Oauth Client Secret (from merchant admin panel)
OpenPayU_Configuration::setOauthClientId('300046');
OpenPayU_Configuration::setOauthClientSecret('c8d4b7ac61758704f38ed5564d8c0ae0');
//set Oauth Client Id and Oauth Client Secret (from merchant admin panel)
OpenPayU_Configuration::setOauthClientId('clent_id');
OpenPayU_Configuration::setOauthClientSecret('clent_secret');
//set Oauth Email and Oauth Ext Customer Id
OpenPayU_Configuration::setOauthEmail('email');
OpenPayU_Configuration::setOauthExtCustomerId('ext_customer_id');
OpenPayU_Configuration::setProxyHost('address');
OpenPayU_Configuration::setProxyPort(8080);
OpenPayU_Configuration::setProxyUser('user');
OpenPayU_Configuration::setProxyPassword('password');
OpenPayU_Configuration::setOauthTokenCache(new OauthCacheFile($directory));
OpenPayU_Configuration::setOauthTokenCache(new OauthCacheMemcached($host, $port, $weight));
$order['continueUrl'] = 'http://localhost/'; //customer will be redirected to this page after successfull payment
$order['notifyUrl'] = 'http://localhost/';
$order['customerIp'] = $_SERVER['REMOTE_ADDR'];
$order['merchantPosId'] = OpenPayU_Configuration::getMerchantPosId();
$order['description'] = 'New order';
$order['currencyCode'] = 'PLN';
$order['totalAmount'] = 3200;
$order['extOrderId'] = '1342'; //must be unique!
$order['products'][0]['name'] = 'Product1';
$order['products'][0]['unitPrice'] = 1000;
$order['products'][0]['quantity'] = 1;
$order['products'][1]['name'] = 'Product2';
$order['products'][1]['unitPrice'] = 2200;
$order['products'][1]['quantity'] = 1;
//optional section buyer
$order['buyer']['email'] = '[email protected] ';
$order['buyer']['phone'] = '123123123';
$order['buyer']['firstName'] = 'Jan';
$order['buyer']['lastName'] = 'Kowalski';
$response = OpenPayU_Order::create($order);
header('Location:'.$response->getResponse()->redirectUri); //You must redirect your client to PayU payment summary page.
$response = OpenPayU_Order::retrieve('Z963D5JQR2230925GUEST000P01'); //as parameter use orderId
$response = OpenPayU_Order::retrieveTransaction('Z963D5JQR2230925GUEST000P01'); //as parameter use orderId
$response = OpenPayU_Order::cancel('Z963D5JQR2230925GUEST000P01'); //as parameter use orderId
$status_update = array(
"orderId" => 'Z963D5JQR2230925GUEST000P01', //as value use ORDER_ID
"orderStatus" => 'COMPLETED'
);
$response = OpenPayU_Order::statusUpdate($status_update);
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$body = file_get_contents('php://input');
$data = trim($body);
$response = OpenPayU_Order::consumeNotification($data);
$response->getResponse()->order->status; //NEW PENDING CANCELED REJECTED COMPLETED WAITING_FOR_CONFIRMATION
header("HTTP/1.1 200 OK");
}
$refund = OpenPayU_Refund::create(
'Z963D5JQR2230925GUEST000P01', //as a value use ORDER_ID
'Money refund', //Description - only for marketplace
'ext-refund-id' // External refund ID,
$response = OpenPayU_Retrieve::payMethods();
$response = OpenPayU_Retrieve::payMethods('en');
$refund = OpenPayU_Token::delete(
'TOKC_EXAMPLE_TOKEN' // as a value use user card token
);
$shop = OpenPayU_Shop::get(
'PUBLIC_SHOP_ID' // Shop ID from Merchant Panel
);