Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 例外:使用beanstream支付网关时,支付信息重复匹配?_Php_Yii_Beanstream - Fatal编程技术网

Php 例外:使用beanstream支付网关时,支付信息重复匹配?

Php 例外:使用beanstream支付网关时,支付信息重复匹配?,php,yii,beanstream,Php,Yii,Beanstream,我的代码如下。问题是,对于每个信用证号码,它只提供一次横切的机会。如何解决同一(测试)信用证号多次横切的问题////////////// // Create a credit card object $card = new BeanstreamCard(); $card->setOwner('Anil Bhattarai'); $card->setNumber('4030000010001234'); $card->setExpiryMonth(8); $card->se

我的代码如下。问题是,对于每个信用证号码,它只提供一次横切的机会。如何解决同一(测试)信用证号多次横切的问题//////////////

// Create a credit card object
$card = new BeanstreamCard();
$card->setOwner('Anil Bhattarai');
$card->setNumber('4030000010001234');
$card->setExpiryMonth(8);
$card->setExpiryYear(18);
$card->setCvd(123);

// Account billing info
$billing = new BeanstreamBilling();
$billing->setEmail('bhattaraianil10@gmail.com');
$billing->setPhone('555-5555');
$billing->setName('Anil Bhattarai');
$billing->setAddress('987 Cardero Street');
$billing->setPostalCode('V6G2G8');
$billing->setProvince('BC');
$billing->setCountry('CA');
$billing->setCity('Vancouver');

// Create a billing profile with the card and billing info
$profile = new BeanstreamProfile('300200320', '6e7550d8304749A7A45A5c9Da8C5a002');

$profile->setCard($card);
$profile->setBilling($billing);
try {
    $profile->save();
} catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
}
// Create and process a new transaction using the passcode
$trans = new BeanstreamTransaction($merchantId);
$trans->setCustomerCode($profile->getCustomerCode());
$trans->setAmount('250.00');
$trans->setOrderNumber(time());
$trans->setRef('My test charge');
$trans->setUsername('rambabu');
$trans->setPassword('6M7sO2psXwsk');
try {
    $result = $trans->process();
} catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
}
class BeanstreamBilling {

    protected $name;
    protected $email;
    protected $phone;
    protected $address;
    protected $postalCode;
    protected $province;
    protected $city;
    protected $country;

    public function getName() {
        return $this->name;
    }

    public function setName($name) {
        $this->name = $name;
    }

    public function getEmail() {
        return $this->email;
    }

    public function setEmail($email) {
        $this->email = $email;
    }

    public function getPhone() {
        return $this->phone;
    }

    public function setPhone($phone) {
        $this->phone = $phone;
    }

    public function getAddress() {
        return $this->address;
    }

    public function setAddress($address) {
        $this->address = $address;
    }

    public function getPostalCode() {
        return $this->postalCode;
    }

    public function setPostalCode($postalCode) {
        $this->postalCode = $postalCode;
    }

    public function getCity() {
        return $this->city;
    }

    public function setCity($city) {
        $this->city = $city;
    }

    public function getProvince() {
        return $this->province;
    }

    public function setProvince($province) {
        $this->province = $province;
    }

    public function getCountry() {
        return $this->country;
    }

    public function setCountry($country) {
        $this->country = $country;
    }

    public function toArray() {
        return array(
            'ordName' => $this->name,
            'ordEmailAddress' => $this->email,
            'ordPhoneNumber' => $this->phone,
            'ordAddress1' => $this->address,
            'ordPostalCode' => $this->postalCode,
            'ordCity' => $this->city,
            'ordProvince' => $this->province,
            'ordCountry' => $this->country,
        );
    }

    public function fromArray($map) {
        $this->setName($map['ordName']);
        $this->setEmail($map['ordEmailAddress']);
        $this->setPhone($map['ordPhoneNumber']);
        $this->setAddress($map['ordAddress1']);
        $this->setPostalCode($map['ordPostalCode']);
        $this->setCity($map['ordCity']);
        $this->setProvince($map['ordProvince']);
        $this->setCountry($map['ordCountry']);
    }
}

class BeanstreamCard {

    protected $owner;
    protected $number;
    protected $expiryMonth;
    protected $expiryYear;
    protected $cvd;

    public function getOwner() {
        return $this->owner;
    }

    public function setOwner($owner) {
        $this->owner = $owner;
    }

    public function getNumber() {
        return $this->number;
    }

    public function setNumber($number) {
        $this->number = $number;
    }

    public function getExpiryMonth() {
        return $this->expiryMonth;
    }

    public function setExpiryMonth($expiryMonth) {
        $this->expiryMonth = $expiryMonth;
    }

    public function getExpiryYear() {
        return $this->expiryYear;
    }

    public function setExpiryYear($expiryYear) {
        $this->expiryYear = $expiryYear;
    }

    public function getCvd() {
        return $this->cvd;
    }

    public function setCvd($cvd) {
        $this->cvd = $cvd;
    }

    public function toArray() {
        return array(
            'trnCardOwner' => $this->owner,
            'trnCardNumber' => $this->number,
            'trnExpMonth' => $this->expiryMonth,
            'trnExpYear' => $this->expiryYear,
            'trnCardCvd' => $this->cvd,
        );
    }

    public function fromArray($map) {
        $this->setOwner($map['trnCardOwner']);
        $this->setNumber($map['trnCardNumber']);
        $this->setExpiryMonth($map['trnExpMonth']);
        $this->setExpiryYear($map['trnExpYear']);
        $this->setCvd($map['trnCardCvd']);
    }
}

class BeanstreamProfile {

    protected $customerCode;
    protected $merchantId;
    protected $passCode;

    const STATUS_NEW      = 'N';
    const STATUS_CLOSE    = 'C';
    const STATUS_DISABLE  = 'D';
    const STATUS_ENABLE   = 'A';

    public function __construct($merchantId, $passCode) {
        $this->merchantId = $merchantId;
        $this->passCode = $passCode;
    }

    public function getMerchantId() {
        return $this->merchantId;
    }

    public function setMerchantId($merchantId) {
        $this->merchantId = $merchantId;
    }

    public function getPassCode() {
        return $this->passCode;
    }

    public function setPassCode($passCode) {
        $this->passCode = $passCode;
    }

    public function getCustomerCode() {
        return $this->customerCode;
    }

    public function setCustomerCode($customerCode) {
        $this->customerCode = $customerCode;
    }

    public function getBilling() {
        return $this->billing;
    }

    public function setBilling($billing) {
        $this->billing = $billing;
    }

    public function getCard($card) {
        return $card;
    }

    public function setCard($card) {
        $this->card = $card;
    }

    public static function load($merchantId, $passCode, $customerCode) {
        $params = array(
            'serviceVersion' => '1.1',
            'responseFormat' => 'QS',
            'operationType'  => 'Q',
            'merchantId'     => $merchantId,
            'passCode'       => $passCode,
            'customerCode'   => $customerCode,
        );

        $request  = new BeanstreamRequest($params, Beanstream::URL_PROFILE);
        $response = $request->makeRequest();

        throw new BeanstreamInvalidProfileException();
    }

    public function save($statusCode = 'A', $validateCard = false) {
        $isNew = empty($this->customerCode);

        $params = array(
            'serviceVersion' => '1.1',
            'responseFormat' => 'QS',
            'operationType'  => $isNew ? 'N' : 'M',
            'cardValidation' => (int)$validateCard,
            'merchantId'     => $this->merchantId,
            'passCode'       => $this->passCode,
            'status'         => $statusCode,
        );

        $params += $this->billing->toArray();

        if ($isNew) {
            if (empty($this->card)) {
                throw new InvalidArgumentException('No credit card data provided.');
            }
            if (empty($this->billing)) {
                throw new InvalidArgumentException('No billing data provided.');
            }
            $params += $this->card->toArray();
        }
        else {
            $params['customerCode'] = $this->customerCode;
        }
        $request = new BeanstreamRequest($params, Beanstream::URL_PROFILE);
        $response = $request->makeRequest();
        if ($response->getValue('responseCode') == 1) {
            $this->customerCode = $response->getValue('customerCode');
            return TRUE;
        }
        else {
            throw new BeanstreamException($response->getValue('responseCode'), $response->getValue('responseMessage'));
        }
    }

    public function enable() {
        return $this->save(self::STATUS_ENABLE);
    }

    public function disable() {
        return $this->save(self::STATUS_DISABLE);
    }

    public function close() {
        return $this->save(self::STATUS_CLOSE);
    }
}

class Beanstream {
    const URL_PROCESS = 'https://www.beanstream.com/scripts/process_transaction.asp';
    const URL_PROFILE = 'https://www.beanstream.com/scripts/payment_profile.asp';
    const URL_RECUR   = 'https://www.beanstream.com/scripts/recurring_billing.asp';
}

class BeanstreamRequest {

    protected $params;
    protected $url;

    public function __construct($params, $url) {
        $this->url = $url;
        $this->params = $params;
    }

    public function makeRequest() {
        $ch = curl_init();
        $data = http_build_query($this->params, NULL, '&');
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_URL, $this->url);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        $response = curl_exec($ch);
        return new BeanstreamResponse($response);
    }
}

class BeanstreamResponse {
    protected $map;

    public function __construct($data) {
        $this->_parse($data);
    }

    protected function _parse($data) {
        parse_str($data, $this->map);
    }

    public function getValue($name) {
        return !empty($this->map[$name]) ? $this->map[$name] : NULL;
    }
}

class BeanstreamTransaction {

    const TYPE_PURCHASE       = 'P';
    const TYPE_REFUND         = 'R';
    const TYPE_VOID_PURCHASE  = 'VP';
    const TYPE_VOID_REFUND    = 'VR';
    const TYPE_PURCHASE_AUTH  = 'PA';

    protected $card;
    protected $billing;
    protected $amount;
    protected $description;
    protected $requestType = 'BACKEND';
    protected $type;
    protected $url;
    protected $username;
    protected $password;

    public function __construct($merchantId) {
        $this->merchantId = $merchantId;
        $this->url = Beanstream::URL_PROCESS;
        $this->type = self::TYPE_PURCHASE;
    }

    public function getType() {
        return $this->type;
    }

    public function setType($type) {
        $this->type = $type;
    }

    public function getCard() {
        return $this->card;
    }

    public function setCard($card) {
        $this->card = $card;
    }

    public function getBilling() {
        return $this->billing;
    }

    public function setBilling($billing) {
        $this->billing = $billing;
    }

    public function getUsername() {
        return $this->username;
    }

    public function setUsername($username) {
        $this->username = $username;
    }

    public function getPassword() {
        return $this->password;
    }

    public function setPassword($password) {
        $this->password = $password;
    }

    public function getAmount() {
        return $this->amount;
    }

    public function setAmount($amount) {
        if (!is_numeric($amount)) {
            throw new InvalidArgumentException('Invalid amount.');
        }
        $this->amount = $amount;
    }

    public function getDescription() {
        return $this->description;
    }

    public function setDescription($description) {
        $this->description = $description;
    }

    public function getOrderNumber() {
        return $this->orderNumber;
    }

    public function setOrderNumber($orderNumber) {
        $this->orderNumber = $orderNumber;
    }

    public function getRef() {
        return $this->ref;
    }

    public function setRef($ref) {
        $this->ref = $ref;
    }

    public function getUrl() {
        return $this->url;
    }

    public function setUrl($url) {
        $this->url = $url;
    }

    public function getCustomerCode() {
        return $this->customerCode;
    }

    public function setCustomerCode($customerCode) {
        $this->customerCode = $customerCode;
    }

    protected function getParams() {
        return array(
            'requestType' => $this->requestType,
            'merchant_id' => $this->merchantId,
            'trnType' => $this->type,
            'trnOrderNumber' => $this->orderNumber,
            'trnAmount' => $this->amount,
            'ref1' => $this->ref,
            'username' => $this->username,
            'password' => $this->password,
        );
    }

    public function process() {
        $params = $this->getParams();
        if (!empty($this->customerCode)) {
            $params['customerCode'] = $this->customerCode;
        }
        else {
            if (!empty($this->billing)) {
                $params += $this->billing->toArray();
            }
            if (!empty($this->card)) {
                $params += $this->card->toArray();
            }
        }
        $request = new BeanstreamRequest($params, Beanstream::URL_PROCESS);
        return $request->makeRequest();
    }
}

class BeanstreamException extends Exception {

    protected $code;
    protected $message;

    public function __construct($code, $message) {
        $this->code = $code;
        $this->message = $message;
    }

    public function __toString() {
        return sprintf('%d - %s', $this->code, $this->message);
    }
}

我终于做到了,我正在分享它,因为我认为它可能对其他像我一样在这方面受苦的人有用。谢谢大家的支持

<?php

        $post_variables = Array(
            "errorPage"=>"https://www.beanstream.com/samples/order_form.asp", // ## NOT REQUIRED ##
            "trnCardNumber"=>"4030000010001234", //test MC number
            "trnExpMonth"=>"12", //testing
            "trnExpYear"=>"12", //testing
            "trnOrderNumber"=>"1234",
            "trnAmount"=>"34.00",
            "trnCardOwner"=>"Anil Bhattarai",
            "ordAddress1"=>"Pokhara",
            "ordAddress2"=>"Nepal",
            "ordCity"=>"Vancouver",
            "ordProvince"=>"BC",
            "ordPostalCode"=>"V6G2G8",
            "ordName"=>"Khachang khuchung",
            "ordEmailAddress"=>"bhattaraianil10@gmail.com",
            "ordPhoneNumber"=>"555-5555",
            "ordCountry"=>"CA",
            //****************************************************************************
            "merchant_id"=>"300200320" // << FILL THIS IN WITH YOUR MERCH ID NUMBER ##
            //****************************************************************************
        );

        // ## MODIFY THIS TEXT TO SUIT YOUR NEEDS ##
        echo ' <div class="BS"> <h3>Please read the following information, and click the button to continue.</h3> <p>You will be directed to a secure payment form hosted by Beanstream, where you may pay for your order using VISA or Mastercard.  Once we receive confirmation of payment from Beanstream, we will ship your order.  Thank you.</p> </div>';

        echo '<label><h4>Proceed to Credit Card Processing &rarr;</h4></label>  ';
        foreach( $post_variables as $name => $value ) {
            echo '<input type="hidden" id="'.$name.'" name="'.$name.'" value="'.htmlspecialchars($value).'" />';
        }


        ?>

        <div id="ram">

        </div>
        <div id="sam"></div>

        <input type="button" id="pay" value="make a payment"/>     
    <script>
        $("#pay").click(function(e)
                {
                    var cardnumber=$('#ocard').val();
                    var trnExpMonth=$('#expiry_month').val();
                    var trnExpYear=$('#expiry_year').val();
                    var trnOrderNumber=$('#ordrrno').val();
                    var trnCardOwner=$('#oname').val();
                    var trnAmount='<?php echo $_SESSION['grandTotal']; ?>';
                    var merchant_id='<?php echo $_SESSION['merchant']; ?>';
                    var trnEmailAddress='<?php echo $_SESSION['myemail']; ?>';
                    alert(trnAmount);
                    var pdata = {};
                    pdata["errorPage"] = "https://www.beanstream.com/samples/order_form.asp";
                    pdata["trnCardNumber"] = cardnumber;
                    pdata["trnExpMonth"] = trnExpMonth;
                    pdata["trnExpYear"] = trnExpYear;
                    pdata["trnOrderNumber"] = trnOrderNumber;
                    pdata["trnAmount"] = trnAmount;
                    pdata["trnCardOwner"] = trnCardOwner;
                    pdata["merchant_id"] = merchant_id;
                    pdata["trnEmailAddress"]=trnEmailAddress;,
                    $.ajax(
                        {
                            url : "https://www.beanstream.com/scripts/process_transaction.asp",
                            type: "POST",
                            data : pdata,
                            success:function(data, textStatus, jqXHR)
                            {
                                $('#ram').html("<b>hello</b>"+data);
                                if (data.indexOf('Transaction Approved') >= 0) {
                                    console.log(data);
                                    parser=new DOMParser();
                                    htmlDoc=parser.parseFromString(data, "text/html");
                                    var table = htmlDoc.body.children[0].children[0].rows[0].cells[0].children[3].children[0].rows[0].cells[1].children[0].innerHTML;
                                    //alert(table.rows[0].cells[0].innerHTML)
                                    alert(table);

                                } else {

                                };
                            },
                            error: function(jqXHR, textStatus, errorThrown)
                            {

                            }
                        });
                    e.preventDefault(); //STOP default action
                });
            </script>

$(“#支付”)。单击(功能(e)
{
var cardnumber=$('#ocard').val();
var trnExpMonth=$(“#到期月”).val();
var trnExpYear=$('到期年').val();
var trnOrderNumber=$('#ordrrno').val();
var trnCardOwner=$('#oname').val();
var trnAmount='';
var商户id=“”;
var trnEmailAddress='';
警报(trnAmount);
var pdata={};
pdata[“错误页面”]=“https://www.beanstream.com/samples/order_form.asp";
pdata[“trnCardNumber”]=卡号;
pdata[“trnExpMonth”]=trnExpMonth;
pdata[“trnExpYear”]=trnExpYear;
pdata[“trnOrderNumber”]=trnOrderNumber;
pdata[“trnAmount”]=trnAmount;
pdata[“trnCardOwner”]=trnCardOwner;
pdata[“商户id”]=商户id;
pdata[“trnEmailAddress”]=trnEmailAddress;,
$.ajax(
{
url:“https://www.beanstream.com/scripts/process_transaction.asp",
类型:“POST”,
数据:pdata,
成功:函数(数据、文本状态、jqXHR)
{
$('#ram').html(“你好”+数据);
if(data.indexOf('Transaction Approved')>=0){
控制台日志(数据);
parser=新的DOMParser();
htmlDoc=parser.parseFromString(数据,“text/html”);
var table=htmlDoc.body.children[0]。children[0]。行[0]。单元格[0]。子[3]。子[0]。行[0]。单元格[1]。子[0]。innerHTML;
//警报(表。行[0]。单元格[0]。innerHTML)
警报(表);
}否则{
};
},
错误:函数(jqXHR、textStatus、errorshown)
{
}
});
e、 preventDefault();//停止默认操作
});
在此处输入代码

$billing = new BeanstreamBilling();
$billing->setEmail('bhattaraianil10@gmail.com');
$billing->setPhone('555-5555');
$billing->setName('Anil Bhattarai');
$billing->setAddress('987 Cardero Street');
$billing->setPostalCode('V6G2G8');
$billing->setProvince('BC');
$billing->setCountry('CA');
$billing->setCity('Vancouver');

我认为这里有错误。因此请删除此部分并尝试,它将解决问题。

基本知识是这一点,但我不想将其重定向到beanstream的网站,以便我可以使我的应用程序在移动浏览器中可靠。
$billing = new BeanstreamBilling();
$billing->setEmail('bhattaraianil10@gmail.com');
$billing->setPhone('555-5555');
$billing->setName('Anil Bhattarai');
$billing->setAddress('987 Cardero Street');
$billing->setPostalCode('V6G2G8');
$billing->setProvince('BC');
$billing->setCountry('CA');
$billing->setCity('Vancouver');