/**
     * Return result of payment via RealVault
     * @param xml $xm from RealexRedirectValidationModuleFrontController::postProcess()
     * @param boolean $ask_dcc (optional)
     * @param boolean $set_dcc (optional)
     * @return xml
     */
    public function requestRealvaultReceiptIn($xm, $ask_dcc = true, $set_dcc = false)
    {
        $url = 'https://epage.payandshop.com/epage-remote-plugins.cgi';
        $tmp = $xm->attributes()->timestamp . '.' . $this->merchant_id . '.' . $xm->orderid . '.' . $xm->amount . '.' . $xm->currency . '.' . $xm->payerref;
        $sha1hash = sha1($tmp);
        $tmp = $sha1hash . '.' . $this->shared_secret;
        $sha1hash = sha1($tmp);
        $xm->addChild('sha1', $sha1hash);
        if ($xm->dcc != '0' && $ask_dcc) {
            $xm_dcc = $this->requestRealvaultDccrate($xm);
        } else {
            $xm_dcc = false;
        }
        if ($xm_dcc) {
            exit;
        }
        $xml = "<request type='receipt-in' timestamp='" . $xm->attributes()->timestamp . "'>";
        $xml .= '<merchantid>' . $this->merchant_id . '</merchantid>
			<account>' . $xm->account . '</account>
			<orderid>' . $xm->orderid . '</orderid>
			<amount currency="' . $xm->currency . '">' . $xm->amount . '</amount>';
        if (!empty($xm->cvn)) {
            $xml .= '<paymentdata>
					<cvn>
						<number>' . $xm->cvn . '</number>
					</cvn>
				</paymentdata>';
        }
        if ($set_dcc) {
            $xml .= '<autosettle flag="1" />';
        } else {
            $xml .= '<autosettle flag="' . $xm->autosettle . '" />';
        }
        if (isset($xm->eci) && !empty($xm->eci)) {
            $xml .= '<mpi>';
            if (isset($xm->cavv) && !empty($xm->cavv) && isset($xm->xid) && !empty($xm->xid)) {
                $xml .= '<cavv>' . $xm->cavv . '</cavv>
				<xid>' . $xm->xid . '</xid>';
            }
            if (isset($xm->eci) && !empty($xm->eci)) {
                $xml .= '<eci>' . $xm->eci . '</eci></mpi>';
            }
        }
        $xml .= '<payerref>' . $xm->payerref . '</payerref>
		<paymentmethod>' . $xm->paymentmethod . '</paymentmethod>';
        if ($set_dcc) {
            $xml .= '
			<dccinfo>
				<ccp>' . $xm->dcc . '</ccp>
				<type>1</type>
				<rate>' . $xm->cardholderrate . '</rate>
				<ratetype>S</ratetype>
				<amount currency="' . $xm->cardholdercurrency . '">' . $xm->cardholderamount . '</amount>
			</dccinfo>';
        }
        $xml .= '<md5hash />
			<sha1hash>' . $sha1hash . '</sha1hash>
			<comments>
				<comment id="1" />
				<comment id="2" />
			</comments>
			<tssinfo>
				<address type="billing">
					<code>' . $xm->billing_code . '</code>
					<country>' . $xm->billing_country . '</country>
				</address>
				<address type="shipping">
					<code>' . $xm->shipping_code . '</code>
					<country>' . $xm->shipping_country . '</country>
				</address>
				<custnum></custnum>
				<varref></varref>
				<prodid></prodid>
			</tssinfo>
		</request>';
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_USERAGENT, 'payandshop.com php version 0.9');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
        $response = curl_exec($ch);
        curl_close($ch);
        $xm_receipt = simplexml_load_string($response);
        if (isset($xm->eci)) {
            $xm_receipt->addChild('eci', $xm->eci);
        }
        if (isset($xm_receipt->dccinfo)) {
            $xm_receipt->addChild('dcc', $xm->dcc);
            $xm_receipt->addChild('dcc_choice', $xm->dcc_choice);
            $xm_receipt->addChild('dcc_rate', $xm_receipt->dccinfo->cardholderrate);
            $xm_receipt->addChild('dcc_cardholder_amount', $xm_receipt->dccinfo->cardholderamount);
            $xm_receipt->addChild('dcc_cardholder_currency', $xm_receipt->dccinfo->cardholdercurrency);
            $xm_receipt->addChild('dcc_merchant_amount', $xm_receipt->dccinfo->merchantamount);
            $xm_receipt->addChild('dcc_merchant_currency', $xm_receipt->dccinfo->merchantcurrency);
        }
        return $xm_receipt;
    }
Пример #2
0
 /**
  * 数据XML编码
  * @param  xml    $xml  XML对象
  * @param  mixed  $data 数据
  * @param  string $item 数字索引时的节点名称
  * @return string xml
  */
 private static function _data2xml($xml, $data, $item = 'item')
 {
     foreach ($data as $key => $value) {
         is_numeric($key) && ($key = $item);
         if (is_array($value) || is_object($value)) {
             $child = $xml->addChild($key);
             self::_data2xml($child, $value, $item);
         } else {
             if (is_numeric($value)) {
                 $child = $xml->addChild($key, $value);
             } else {
                 $child = $xml->addChild($key);
                 $node = dom_import_simplexml($child);
                 $node->appendChild($node->ownerDocument->createCDATASection($value));
             }
         }
     }
 }