2011-12-28 37 views
2

我需要在我的php代码中实现BeanStream支付网关。我是支付网关实现的新手。任何人都可以帮助我处理任何演示项目或脚本吗?事先谢谢。需要Beanstream支付网关集成的脚本

+0

你能详细说明 - 你有没有搜索过一点?你有尝试过什么吗? –

+0

我的网站有购物车信用卡功能。客户提供了Beanstream的merchat帐户API密钥,API密码和签名。我已经搜索了整合脚本。但我找不到。任何人都可以帮助脚本吗? – user1107906

回答

2

我知道这是一个老问题,但因为我只是在我的代码实现的Beanstream支付网关,我想我会回答反正备案:

一旦你有Beanstream一个帐户,你就可以访问他们的API手册,这些手册提供了关于所有请求和响应字段的良好文档。您可以使用PHP中的curl库很容易地连接到Beanstream API。这里是一个基于他们的文档进行简单付款的示例方法($ global_ccauth只是一个ORM对象,它包含我的请求信息,每次存储在我的数据库中,包括来自Beanstream的响应字符串,但是请小心,并且您可能会想混淆信用卡号码在ORM模型之前,它被保存到数据库中,像我这样做):

public static function do_payment($global_ccauth, $submitted_card_number) { 
    $payment_result = array(
     'status' => FALSE, 
     'response' => array(), 
    ); 

    // attempt to process the payment using CURL and a POST request to the Beanstream server as per Beanstream's example 
    $request = curl_init(); 

    // Get curl to POST 
    curl_setopt($request, CURLOPT_POST, 1); 
    curl_setopt($request, CURLOPT_SSL_VERIFYHOST, 0); 
    curl_setopt($request, CURLOPT_SSL_VERIFYPEER, 0); 
    curl_setopt($request, CURLOPT_RETURNTRANSFER, 1); // return the results instead of echoing them 
    curl_setopt($request, CURLOPT_URL, BEANSTREAM_URL); 

    // These are the transaction parameters that we will POST 
    $auth_parameters = "requestType=BACKEND"; 
    $auth_parameters .= "&merchant_id=" . BEANSTREAM_MERCHANT; 
    $auth_parameters .= "&username=" . BEANSTREAM_API_USER; 
    $auth_parameters .= "&password=" . BEANSTREAM_API_PASS; 
    $auth_parameters .= "&trnCardOwner=" . $global_ccauth->trnCardOwner; 
    $auth_parameters .= "&trnCardNumber=". $submitted_card_number; 
    $auth_parameters .= "&trnExpMonth=" . $global_ccauth->trnExpMonth; 
    $auth_parameters .= "&trnExpYear=" . $global_ccauth->trnExpYear; 
    //$auth_parameters .= "&trnCardCvd="; 
    $auth_parameters .= "&trnOrderNumber=" . $global_ccauth->trnOrderNumber ; 
    $auth_parameters .= "&trnAmount=" . $global_ccauth->trnAmount; 
    $auth_parameters .= "&ordName=" . $global_ccauth->ordName; 
    $auth_parameters .= "&ordEmailAddress=" . $global_ccauth->ordEmailAddress; 
    $auth_parameters .= "&ordPhoneNumber=" . $global_ccauth->ordPhoneNumber; 
    $auth_parameters .= "&ordAddress1=" . $global_ccauth->ordAddress1; 
    $auth_parameters .= "&ordAddress2=" . $global_ccauth->ordAddress2; 
    $auth_parameters .= "&ordCity=" . $global_ccauth->ordCity; 
    $auth_parameters .= "&ordProvince=" . $global_ccauth->ordProvince; 
    $auth_parameters .= "&ordPostalCode=" . $global_ccauth->ordPostalCode; 
    $auth_parameters .= "&ordCountry=" . $global_ccauth->ordCountry; 

    curl_setopt($request, CURLOPT_POSTFIELDS, $auth_parameters); 

    // Now POST the transaction. $txResult will contain Beanstream's response 
    $auth_result = curl_exec($request); 
    curl_close($request); 

    if ($auth_result !== FALSE) { 
     // save the raw results 
     $global_ccauth->response = $auth_result; 
     $global_ccauth->save(); 

     // parse the results 
     parse_str($auth_result, $parsed_result); 
     $payment_result['response'] = $parsed_result; 
     if (! empty($parsed_result['trnApproved']) && $parsed_result['trnApproved'] == 1) { 
      // the request was approved 
      $payment_result['status'] = TRUE; 
     } else { 
      // the request was not approved 
      // do something smart 
     } 
    } else { 
     // curl POST request failed 
     // do something smart 
    } 

    return $payment_result; 
} 

我也实施了定期付款用于自动处理每月支付,它似乎运作良好。您只需根据API文档调整您发送的参数即可。