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

阿尼尔·巴塔莱(Anil Bhattarai)100

我的代码如下。问题在于每一个学分都没有。它仅提供了一次横切的机会。如何从同一个(测试)学分编号多次横断问题?///////////////

// 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('[email protected]');
$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);
    }
}
阿尼尔·巴塔莱(Anil Bhattarai)100

最后,我制作了它,并与大家分享,因为我认为它对过去像我这样遭受痛苦的其他人可能很有用。并感谢大家的支持。

<?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"=>"[email protected]",
            "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>

enter code here

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

为什么付款网关使用校验和?

来自分类Dev

使用PHP的Suregate(付款网关)集成

来自分类Dev

PayUMoney付款网关问题

来自分类Dev

巴基斯坦付款网关

来自分类Dev

Python Stripe付款网关

来自分类Dev

Cashu付款网关

来自分类Dev

ModPay付款网关HowTo

来自分类Dev

Woocommerce BACS付款网关帐户详细信息修改

来自分类Dev

禁用特定付款方式的付款网关

来自分类Dev

付款后PayUMoney付款网关错误

来自分类Dev

WooCommerce-隐藏付款网关

来自分类Dev

Ogone付款网关集成php

来自分类Dev

覆盖Woocommerce付款网关模板

来自分类Dev

Magento付款网关/在线退款

来自分类Dev

条纹支付网关使用PayumBundle创建定期付款

来自分类Dev

识别重复付款

来自分类Dev

带有Infusionsoft付款网关的Wordpress wpmember插件付款方法

来自分类Dev

列出所有在付款时最大的付款

来自分类Dev

使用Braintree下拉式用户界面选择用于重复计费的付款方式-或:查找PaymentMethodNonce的付款方式

来自分类Dev

使用Braintree下拉式用户界面选择用于重复计费的付款方式-或:查找paymentMethodNonce的付款方式

来自分类Dev

使用INVNUM的Paypal NVP TransanctionSearch不返回任何付款信息

来自分类Dev

如何使用 Razorpay PHP API 获取付款详细信息?

来自分类Dev

使用Quickbook(Intuit付款)实施付款流程

来自分类Dev

使用Paypal Payouts API退款并避免重复付款

来自分类Dev

WooCommerce订单状态从付款网关更改

来自分类Dev

Phonegap中是否可以集成付款网关?

来自分类Dev

从WebView中的付款网关获取回调

来自分类Dev

Laravel付款网关中的csrf异常

来自分类Dev

Paytab付款网关不起作用

Related 相关文章

热门标签

归档