31.1.12

Platnosci payment gateway integration php





  • Create a Account in Platnosci
  • Get these details
  • PlatnosciId
  •  Authorisationkey
  •  Platnosci signature Key1
  •  Platnosci signature Key2
  •  Platnosci gateway URL
  • Before the passing the Payment details to payment Gateway we need to store the details of what we are passing such as unique id,amount,product id like that
  • After inserting these datas into the database we need to redirect to a html page

Sample html page

<form name="platnosci_payment"  action="https://www.platnosci.pl/paygw/ISO/NewPayment"  method="post">
<input type="hidden" name="first_name" value="firstname" />
<input type="hidden" name="last_name" value="lastname" />
<input type="hidden" name="email" value="email" />
<input type="hidden" name="address" value="address" />
<input type="hidden" name="city" value="city" />
<input type="hidden" name="platno_postcode" value="postcode" />
<input type="hidden" name="platnoTotal_price" value="Total_price" />
<input type="hidden" name="pos_id" value="platno_pos_id" />
<input type="hidden" name="pos_auth_key" value="platno_pos_auth_key" />
<input type="hidden" name="session_id" value="uniqueid" />
<input type="hidden" name="amount" value="Total_price*100" />
<input type="hidden" name="desc" value="description" />
<input type="hidden" name="client_ip" value="ClientIp Address" />
<input type="hidden" name="js" value="1" />
</form>

-----------------------------------------------------------------
After the Success full payment we will be returned to the success url

we need to validate the return parameters to check whether the payment was success or failure

checking success/failure payment

     $statusMap=array(
           '1'=>'new',
           '2'=>'cancelled',
           '3'=>'rejected',
           '4'=>'started',
           '5'=>'awaiting collection',
           '7'=>'payment rejected, funds have been transferred by a client after the transaction was cancelled, or funds
        could not be returned automatically; such situations will be monitored and explained by the Platnosci team',
           '99'=>'Accepted',
           '888'=>'incorrect status - we ask user to contact us'
       );
    //$response  Contains all the responses send to success url
    //$purchaseAmount amount of the Purchased Item
        $time = time();
        $unique_id = $response['session_id'];
        $sign_key = $platnosci_sign_key;
        $platno_id = $platnosci_id;
        $gateway_url = $gateway_url;
        $signature = md5($platno_id.$unique_id.$time.$sign_key);

        $Params=array('pos_id' => $platno_id,
                    'session_id' => $unique_id,
                    'ts' => $time,
                    'sig' => $signature );

    function checkStatus($Params,$gateway_url){
       
        $client = new Zend_Http_Client();
        $client->setUri($gateway_url.'/ISO/Payment/get/xml');
        $client->setParameterPost($Params);
        $response = $client->request('POST');
        $responseBody = $response->getBody();
        $result=array();
        try{
            $xml = new SimpleXMLElement($responseBody);         
            $result['status']=$xml->trans->status;
            $result['trans_id']=$xml->trans->id;
            $result['amount']=$xml->trans->amount;  

        }catch (Exception $e)
        {
            $result['status']="";
            $result['trans_id']="";
            $result['amount']="";
        }
        return $result;
    }
    $result = $this->checkStatus($Params,$gateway_url);
   
    $tranns_amount=($result['amount']/100);

    if( $result['status'] == 99 && $tranns_amount ==$purchaseAmount) {
        // Payment is Success   
    }else{
        //Payment Failed
        echo $statusMap[$result['status']];die;
    }



No comments:

Post a Comment