需要 Beanstream 支付网关集成脚本

发布于 2024-12-23 07:07:01 字数 75 浏览 3 评论 0原文

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

I need to implement BeanStream payment gateway in my php code.I am new in payment gateway implementation. Can anybody help me with any demo project or scripts? prior thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

巡山小妖精 2024-12-30 07:07:01

我知道这是一个老问题,但由于我刚刚在我的代码中实现了 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 文档调整发送的参数即可。

I know this is an old question, but since I just implemented the Beanstream payment gateway in my code I thought I would answer for the record anyway:

Once you have an account with Beanstream you will be able to access their API manuals which provide some good documentation on all of the request and response fields. You can use the curl library in PHP to connect to the Beanstream API this very easily. Here is a sample method for performing a simple payment based on their documentation ($global_ccauth is just an ORM object that contains my request information, which I store each time in my database, including the response string from Beanstream, but BE CAREFUL AND YOU PROBABLY WANT TO obfuscate the credit card number in the ORM model before it is saved to the database, like I do):

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

I have also implemented their recurring payments for processing monthly payments automatically and it seems to be working well. You just have to adjust the parameters you send as per their API documentation.

铁轨上的流浪者 2024-12-30 07:07:01

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

PHP-Payments seems to be what you're looking for http://payments.calvinfroedge.com/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文