27.12.11

Przelewy-payment-gateway-integration php




 
   INTEGRATE PRZELEWY PAYMENT GATEWAY
              -------------------------------------

1. Create account in Przelewy payment gateway
2. Get p24_id_sprzedawcy
3. Przelewy uses redirect model for payment
   ie redirecting to the merchant site for making payment
4. so before proceeding the payment we need to save the buy details such as
   uniqueid, quantity, price, product details, etc...
5. After saving these details render a html with the details and make it auto submit or
   make the user to submit once more with the details already entered

 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<?php
        $actionUrl = "https://secure.przelewy24.pl/index.php";
        $p24_id_sprzedawcy = 58952;//p24_id_sprzedawcy

            $prz_postdata = array("lastname" => $paymentdata['lastname'],
                "p24_session_id" => $unique_id,// should be unique in every payment
                "p24_id_sprzedawcy" => $p24_id_sprzedawcy, //merchant id
                "p24_kwota" => $amount,//pass amount as it is 10.30
                "p24_comment" => "Deal no:".$dealdetails['DealId']."source:".$dealdetails['test'],
                "p24_klient" => $paymentdata['firstname'],// name of user
                "p24_adres" => $paymentdata['address'],//address of user
                "p24_kod" => $paymentdata['postcode'],//post code of user
                "p24_miasto" => $paymentdata['city'],// city details
                "p24_kraj" => "PL",//country
                "p24_email" => $paymentdata['email'],//email of user
                "p24_language" => "pl",//language
                "p24_return_url_ok" => "BASEURL/success", // success return url
                "p24_return_url_error" => "BASEURL/error",// error return url
                "actionUrl"=>$actionUrl);


?>



<form name="przelewy24payment" action="<?php echo $this->prz_postdata['actionUrl'];?>" onload="submit();" method="post">
<input type="hidden" name="p24_session_id" value="<?php echo $this->prz_postdata['p24_session_id']?>" />
<input type="hidden" name="p24_id_sprzedawcy" value="<?php echo $this->prz_postdata['p24_id_sprzedawcy']?>" />
<input type="hidden" name="p24_kwota" value="<?php echo $this->prz_postdata['p24_kwota']*100?>" />
<input type="hidden" name="p24_opis" value="<?php echo $this->prz_postdata['p24_comment']?>" />
<input type="hidden" name="p24_klient" value="<?php echo $this->prz_postdata['p24_klient']?>" />
<input type="hidden" name="p24_adres" value="<?php echo $this->prz_postdata['p24_adres']?>" />
<input type="hidden" name="p24_kod" value="<?php echo $this->prz_postdata['p24_kod']?>" />
<input type="hidden" name="p24_miasto" value="<?php echo $this->prz_postdata['p24_miasto']?>" />
<input type="hidden" name="p24_kraj" value="<?php echo $this->prz_postdata['p24_kraj']?>" />
<input type="hidden" name="p24_email" value="<?php echo $this->prz_postdata['p24_email']?>" />
<input type="hidden" name="p24_language" value="<?php echo $this->prz_postdata['p24_language']?>" />
    <!-- <input type="hidden" name="p24_karta" value="0/1" />-->
<input type="hidden" name="p24_return_url_ok" value="<?php echo $this->prz_postdata['p24_return_url_ok']?>" />
<input type="hidden" name="p24_return_url_error" value="<?php echo $this->prz_postdata['p24_return_url_error']?>" />
</form>


    <script>
    document.przelewy24payment.submit();
    </script>

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

6. After the successfull Completion of Payment Przelewy will return the details of the payment via url
7. we get orderid ,session id and price of the product
8. the next step is to verify is that the confirmed purchase is a manupulated one or not
9. ie any data send to the payment gateway is changed by the user or not

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

<?php
/*
  NOTE: No testing option

*/


class Przelewy {
  var $przdata = array();
  var $submiturl;
  var $trxstaturl;
  var $trx_result = array();
  var $comments = array();

  function Przelewy()
  {
    $this->submiturl = 'https://secure.przelewy24.pl/index.php';
    $this->trxstaturl = "https://secure.przelewy24.pl/transakcja.php";
  }


  /**
   * Verify transaction
   */
  function p24_weryfikuj($p24_id_sprzedawcy, $p24_session_id, $p24_order_id,$p24_kwota="")
  {
      $P = array(); $RET = array();
    $url = "https://secure.przelewy24.pl/transakcja.php";
    $P[] = "p24_id_sprzedawcy=".$p24_id_sprzedawcy;
    $P[] = "p24_session_id=".$p24_session_id;
    $P[] = "p24_order_id=".$p24_order_id;
    $P[] = "p24_kwota=".$p24_kwota;
    $user_agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_POST,1);
    if(count($P)) curl_setopt($ch, CURLOPT_POSTFIELDS,join("&",$P));
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
    if(count($H)) curl_setopt ($ch, CURLOPT_HTTPHEADER, $H);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    $result=curl_exec ($ch);
    curl_close ($ch);
    $T = explode(chr(13).chr(10),$result);
    foreach($T as $line){
        $line = ereg_replace("[\n\r]","",$line);
        if($line != "RESULT" and !$res) continue;
        if($res)$RET[] = $line;
        else $res = true;
    }
    return $RET;
  }
?>

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++

    $p24_session_id = $resp_data["p24_session_id"];
    $p24_order_id = $resp_data["p24_order_id"];
    $p24_id_sprzedawcy = $p24_id_sprzedawcy; // this id should be from our Temp DB
    $p24_kwota = $userpaymentdetails->amount*100; // this detail should be from our temp DB

    $paymentObject = new Przelewy();
    $verifydata = $paymentObject->p24_weryfikuj($p24_id_sprzedawcy, $p24_session_id, $p24_order_id,$p24_kwota="");
    if($verifydata[0] == "TRUE") {
    // the Payment was successfull and get the details of the product with
    // the unique id update the DB of purchase accordingly
    }else{
    // the Payment was Failure and redirect to error Page and track the retyrned details for later verification
    }

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++



No comments:

Post a Comment