在PHP中集成paynamics支付网关

时间:2018-04-24 08:03:52

标签: php payment-gateway

如何在我的网站中将paynamics集成为我的支付网关。 注意:Paynamics仅在菲律宾独家使用。

我有以下代码,但是当我提交表单时,我总是得到事务失败,它给了我“签名验证失败”。我不知道签名是否正确。

<?php 

$_mid = "xxxxxxxxxxxxxxxxxxx"; //<-- your merchant id
$_requestid = substr(uniqid(), 0, 13);
// $_responseid = rand(9,100);
// $_ipaddress = "192.168.10.1";
$_ipaddress = "192.168.51.1";
$_noturl = "http://localhost/aspr/checkout-2/"; // url where response is posted
$_resurl = "http://localhost/aspr/checkout-2/"; //url of merchant landing page
$_cancelurl = "http://localhost/aspr/cancel/"; //url of merchant landing page
$_fname = "Juan"; // kindly set this to first name of the cutomer
$_mname = "O"; // kindly set this to middle name of the cutomer
$_lname = "Dela Cruz"; // kindly set this to last name of the cutomer
$_addr1 = "1609 Cityland 10 HV Dela Costa St.Salecedo Village"; // kindly set this to address1 of the cutomer
$_addr2 = "longos malolos";// kindly set this to address2 of the cutomer
$_city = "makati"; // kindly set this to city of the cutomer
$_state = "MM"; // kindly set this to state of the cutomer
$_country = "PH"; // kindly set this to country of the cutomer
$_zip = "1200"; // kindly set this to zip/postal of the cutomer
$_sec3d = "enabled"; // 
$_email = "technical@paynamics.net"; // kindly set this to email of the cutomer
$_phone = "3308772"; // kindly set this to phone number of the cutomer
$_mobile = "09178134828"; // kindly set this to mobile number of the cutomer
$_clientip = $_SERVER['REMOTE_ADDR'];

$_amount = number_format((float)20, 2, '.', ''); // kindly set this to the total amount of the transaction. Set the amount to 2 decimal point before generating signature.
$_currency = "PHP"; //PHP or USD

$forSign = $_mid . 
        $_requestid . 
        $_ipaddress . 
        $_noturl . 
        $_resurl .  
        $_fname . 
        $_lname . 
        $_mname . 
        $_addr1 . 
        $_addr2 . 
        $_city . 
        $_state . 
        $_country . 
        $_zip . 
        $_email . 
        $_phone . 
        $_clientip . 
        $_amount . 
        $_currency . 
        $_sec3d; 

        $cert = "xxxxxxxxxxxxxxxxxxxxxxxxxx";//<-- your merchant key

$_sign = hash("sha512", $forSign.$cert);

$strxml = "";
$strxml .= "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";

$strxml .= "<Request>";
    $strxml .= "<mid>" . $_mid . "</mid>";
    $strxml .= "<request_id>" . $_requestid . "</request_id>";
    $strxml .= "<ip_address>" . $_ipaddress . "</ip_address>";
    $strxml .= "<notification_url>" . $_noturl . "</notification_url>";
    $strxml .= "<response_url>" . $_resurl . "</response_url>";
    $strxml .= "<cancel_url>" . $_cancelurl . "</cancel_url>";
    $strxml .= "<mtac_url>".$_resurl."</mtac_url>"; // pls set this to the url where your terms and conditions are hosted
    $strxml .= "<descriptor_note></descriptor_note>"; // pls set this to the descriptor of the merchant ""
    $strxml .= "<fname>" . $_fname . "</fname>";
    $strxml .= "<lname>" . $_lname . "</lname>";
    $strxml .= "<mname>" . $_mname . "</mname>";
    $strxml .= "<address1>" . $_addr1 . "</address1>";
    $strxml .= "<address2>" . $_addr2 . "</address2>";
    $strxml .= "<city>" . $_city . "</city>";
    $strxml .= "<state>" . $_state . "</state>";
    $strxml .= "<country>" . $_country . "</country>";
    $strxml .= "<zip>" . $_zip . "</zip>";
    $strxml .= "<email>" . $_email . "</email>";
    $strxml .= "<phone>" . $_phone . "</phone>";
    $strxml .= "<mobile>" . $_mobile . "</mobile>";
    $strxml .= "<amount>" . $_amount . "</amount>";
    $strxml .= "<currency>" . $_currency . "</currency>";
    $strxml .= "<pmethod></pmethod>";
    $strxml .= "<expiry_limit></expiry_limit>";
    $strxml .= "<trxtype>Sale</trxtype>";
    $strxml .= "<client_ip>" . $_clientip . "</client_ip>";
    $strxml .= "<mlogo_url></mlogo_url>";// pls set this to the url where your logo is hosted

    // $item['name'] = 'item1';
    // $item['qty'] = 0;
    // $item['amount'] = 100.00;
    $amt = number_format((float)10, 2, '.', '');

    $strxml .= "<orders>";
        $strxml .= "<items>";
            // item 1
            $strxml .= "<Items>";
                $strxml .= "<itemname>item 1</itemname>";
                $strxml .= "<quantity>1</quantity>";
                $strxml .= "<amount>".$amt."</amount>";
            $strxml .= "</Items>";

            // item 2
            $strxml .= "<Items>";
                $strxml .= "<itemname>item 2</itemname>";
                $strxml .= "<quantity>1</quantity>";
                $strxml .= "<amount>".$amt."</amount>";
            $strxml .= "</Items>";
        $strxml .= "</items>";
    $strxml .= "</orders>";

    $strxml .= "<secure3d>" . $_sec3d . "</secure3d>";
    $strxml .= "<signature>" . $_sign . "</signature>";
$strxml .= "</Request>";

$b64string =  base64_encode($strxml);

 ?> 

以下是提交表单:

<form name="surecollect" id="surecollect" method="post" action="https://testpti.payserv.net/webpaymentv2/default.aspx">
    <input type="hidden" name="paymentrequest" value="<?php echo $b64string; ?>">
    <input type="submit" name="submit" value="Submit">
</form>

1 个答案:

答案 0 :(得分:0)

设置您的有效期限:此功能将帮助date('yyyy-MMddTHH:mm') 然后将有效的WAN IP设置为IP地址,并使用SSL设置URL。