需要Beanstream支付网关集成的脚本

时间:2011-12-28 12:11:49

标签: php payment-gateway beanstream

我需要在我的php代码中实现BeanStream支付网关。我是支付网关实现的新手。有人可以帮我解决任何演示项目或脚本吗?事先谢谢。

2 个答案:

答案 0 :(得分: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文档调整发送的参数。

答案 1 :(得分:0)

PHP-Payments似乎是您正在寻找的http://payments.calvinfroedge.com/