Giter Club home page Giter Club logo

openpayu_php's Introduction

Build Status Code Climate

OpenPayU PHP Library 1.x and 2.x

The OpenPayU PHP library provides integration access to the PayU Gateway API ver. 1 and ver. 2

Dependencies

The following PHP extensions are required:

  • cURL
  • hash
  • XMLWriter
  • XMLReader

Documentation

Full implementation guide [English] [Polish].

Quick guide [English] [Polish].

Installation

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
    );

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.