2012-05-07 2 views
1

장바구니를 만들고 있습니다. 지불 게이트웨이로 가기 전에 주문을 저장하고 싶습니다. 결제 게이트웨이를 사용하려면 외부 주소로 POST를 보내야하지만 컨트롤러 작업에서이를 수행하는 방법은 필요하지 않습니다.POST 변수를 외부 URL로 보내는 방법은 무엇입니까?

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? 
} 

답변

1

사용 cURL to post data : 우리의 웹 사이트 (bpremium.com) 우리가 아약스를 통해 우리의 결제 시스템을 실행에

//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); 
+0

게시 변수가있는 URL을 열어야합니다! 태그 양식처럼 제출하고 withouth html – Mauro

+0

컬은 당신을 위해 그것을 할 수 있습니다. – dubvfan87

+0

같은 창에서 어떻게 열 수 있습니까? – Mauro

0

, 우리의 웹 사이트는 "판매를 만들"또는 웹 서비스를 통해 "업데이트 양"에 같은 명령을 전송 특정 URL 및 해당 URL은 장바구니의 현재 상태를 기록하고 세션에서 판매 ID를 저장합니다.

우리가 TPV에 도착하면 webservice를 실행하여 생성 된 서명 된 해시 형식의 HTML을 가져 와서 버튼 하나만 누르면됩니다.

이 기술은 속도가 빠르기 때문에 리디렉션을 유지하고 사용자를 기다릴 필요가 없으므로 훨씬 덜 무겁고 TPV를 창에 열어 입력하면 merchantURL이 성공하거나 실패 할 때 TPV 게이트웨이에서 POST 데이터를 포착하십시오.

관련 문제