1

我正在做一个购物车。我想在去支付网关之前保存订单。我的支付网关需要我发送一个 POST 到外部地址,而不是如何通过控制器操作来完成。

public function executeBuy(sfWebRequest $request)
{
  sfProjectConfiguration::getActive()->loadHelpers('Url');

  // save the order
  $this->order = new Order();
  $this->save
  //etc....

  //go to TPV Payment gateway
  $dsAmount       = (float)$order->getPriceWithShipping() * 100;
  $dsOrder        = (int)$order->getId() * 400;
  $dsMerchantCode = (int)sfConfig::get('app_tpv_merchant_code');
  $dsCurrency     = (int)sfConfig::get('app_tpv_merchant_currency');
  $dsMerchantURL  = url_for('cart/ipn', true, array(
    'sf_culture' => $this->getUser()->getCulture(),
  ));
  $options = array(
    'Ds_Merchant_Amount'            => $dsAmount,
    'Ds_Merchant_Currency'          => $dsCurrency,
    'Ds_Merchant_Order'             => $dsOrder,
    'Ds_Merchant_Titular'           => $order->getAddress()->getCustomer()->getNameAndLastName(),
    'Ds_Merchant_MerchantCode'      => $dsMerchantCode,
    'Ds_Merchant_MerchantURL'       => $dsMerchantURL,
    'Ds_Merchant_MerchantSignature' => $digest,
    'Ds_Merchant_Terminal'          => $dsCurrency
  );

  //how to send post $options variables to external url?
}
4

2 回答 2

1

使用cURL 发布数据

//set POST variables
$dsMerchantURL = url_for('cart/ipn', true, array(
  'sf_culture' => $this->getUser()->getCulture(),
));

$options = array(
  'Ds_Merchant_Amount' => urlencode($dsAmount),
  'Ds_Merchant_Currency' => urlencode($dsCurrency),
  'Ds_Merchant_Order' => urlencode($dsOrder),
  'Ds_Merchant_Titular' => urlencode($order->getAddress()->getCustomer()->getNameAndLastName()),
  'Ds_Merchant_MerchantCode' => urlencode($dsMerchantCode),
  'Ds_Merchant_MerchantURL' => urlencode($dsMerchantURL),
  'Ds_Merchant_MerchantSignature' => urlencode($digest),
  'Ds_Merchant_Terminal' => urlencode($dsCurrency)
);

//url-ify the data for the POST
foreach($options as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'& ');

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $dsMerchantURL);
curl_setopt($ch,CURLOPT_POST, count($options));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);

//execute post
$result = curl_exec($ch);

//close connection
curl_close($ch);
于 2012-05-07T16:51:44.767 回答
0

在我们的网站(bpremium.com)上,我们通过 ajax 运行我们的支付系统,我们的网站通过网络服务向特定 url 发送诸如“创建销售”或“更新数量”之类的命令,这些 url 记录您购物车的当前状态并存储销售会话中的 ID。

然后当我们到达 TPV 时,我们执行一个 web 服务来获取表单的 html,生成、签名和散列,只需按下一个按钮即可。

这种技术非常适合高速,因为您不需要继续重定向和强迫用户等待,它的重量要轻得多,这意味着您只需将 TPV 打开到一个窗口中,填写它,merchantURL 就会捕获 POST 数据从 TPV 网关成功或失败时。

于 2012-07-09T22:30:23.437 回答