【问题标题】:Need script for Beanstream payment gateway integration需要 Beanstream 支付网关集成脚本
【发布时间】:2011-12-28 12:11:49
【问题描述】:

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

【问题讨论】:

  • 你能详细说明一下 - 你搜索过吗?你有没有尝试过?
  • 我的网站有带信用卡功能的购物车。客户已提供 Beanstream 商户账户 API Key、API 密码和签名。我搜索了集成脚本。但我找不到。谁能帮忙写脚本?

标签: php payment-gateway beanstream


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-01
      • 2013-09-16
      • 2011-05-05
      • 2016-02-02
      • 2012-05-21
      • 2011-03-10
      • 2013-07-21
      • 2015-03-19
      相关资源
      最近更新 更多