使用cUrl打开支付网关

时间:2012-07-24 13:58:25

标签: php curl symfony1 payment-gateway

我正在尝试访问支付网关。在银行的例子中有一个简单的html FORM,但我想通过cURL来做。 我的问题是当我尝试访问支付网关时没有看到css(网关样式表)和javascript失败。 有没有办法避免这些错误?

    $url = sfConfig::get('app_tpv_url');

    $dsOrder = $this->getDSOrder($order);
    $dsAmount = (float)$order->getPriceWithShipping() * 100;
    $dsCurrency = sfConfig::get('app_tpv_merchant_currency');
    $dsMerchantCode = sfConfig::get('app_tpv_merchant_code');
    $dsName = sfConfig::get('app_tpv_merchant_name');
    $dsLanguage = ($this->getUser()->getCulture() == 'es') ? 1 : 2;
    $dsTerminal = sfConfig::get('app_tpv_merchant_terminal');
    $dsSignature = sfConfig::get('app_tpv_merchant_signature');
    $dsTransactionType = 0;

    sfProjectConfiguration::getActive()->loadHelpers('Url');
    $dsUrl = url_for('cart_ipn', array('sf_culture' => $this->getUser()->getCulture(),), true);

    $dsStringResult = $dsAmount + $dsOrder + $dsMerchantCode + $dsCurrency + $dsTransactionType + $dsSignature;
    $digest = sha1($dsStringResult);

    $options = array(
        'Ds_Merchant_Amount' => $dsAmount,
        'Ds_Merchant_Currency' => $dsCurrency,
        'Ds_Merchant_Order' => $dsOrder,
        'Ds_Merchant_MerchantCode' => $dsMerchantCode,
        'Ds_Merchant_MerchantName' => $dsName,
        'Ds_Merchant_ConsumerLanguage' => $dsLanguage,
        'Ds_Merchant_Terminal' => $dsTerminal,
        'Ds_Merchant_MerchantSignature' => $digest,
        'DS_Merchant_TransactionType' => $dsTransactionType,
        'Ds_Merchant_MerchantURL' => $dsUrl
    );

    $fields_string = '';
    foreach ($options as $key => $value) {
        $fields_string .= $key . '=' . $value . '&';
    }

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_USERAGENT, $this->getContext()->getRequest()->getHttpHeader('User-Agent'));

    curl_exec($ch);

    curl_close($ch);

0 个答案:

没有答案