Welcome Guest, Not a member yet? Register   Sign In
How to make payment gate way?
#11

[eluser]barryskidmore[/eluser]
Code:
function parse_response() {
        $this->x_response_length = substr_count($this->x_response,'|');
        $this->x_response_length++;
        for ($this->x_response_segment = 1; $this->x_response_segment <= $this->x_response_length; $this->x_response_segment++) {
            $this->x_position = strpos($this->x_response,'|');
            if ($this->x_position === false) {
            } else {
                $this->x_position++;
                $this->x_sub_string = substr($this->x_response,0,$this->x_position);
                $this->x_actual_string = substr($this->x_sub_string,0,-1);
                if ($this->x_actual_string == '') {
                    $this->x_actual_string = 'NO RESPONSE';
                }
                // Do stuff with string
                switch ($this->x_response_segment) {
                    case 1:
                        $this->x_result['ResponseCode'] = $this->x_actual_string;
                        break;
                    case 2:
                        $this->x_result['SubCode'] = $this->x_actual_string;
                        break;
                    case 3:
                        $this->x_result['ReasonCode'] = $this->x_actual_string;
                        break;
                    case 4:
                        $this->x_result['ReasonText'] = $this->x_actual_string;
                        break;
                    case 5:
                        $this->x_result['ApprovalCode'] = $this->x_actual_string;
                        break;
                    case 6:
                        $this->x_result['ResultCode'] = $this->x_actual_string;
                        break;
                    case 7:
                        $this->x_result['TransactionId'] = $this->x_actual_string;
                        break;
                    case 8:
                        $this->x_result['InvoiceNumber'] = $this->x_actual_string;
                        break;
                    case 9:
                        $this->x_result['Description'] = $this->x_actual_string;
                        break;
                    case 10:
                        $this->x_result['Amount'] = $this->x_actual_string;
                        break;
                    case 11:
                        $this->x_result['Method'] = $this->x_actual_string;
                        break;
                    case 12:
                        $this->x_result['TransactionType'] = $this->x_actual_string;
                        break;
                    case 13:
                        $this->x_result['CustomerId'] = $this->x_actual_string;
                        break;
                    case 14:
                        $this->x_result['FirstName'] = $this->x_actual_string;
                        break;
                    case 15:
                        $this->x_result['LastName'] = $this->x_actual_string;
                        break;
                    case 16:
                        $this->x_result['Company'] = $this->x_actual_string;
                        break;
                    case 17:
                        $this->x_result['Address'] = $this->x_actual_string;
                        break;
                    case 18:
                        $this->x_result['City'] = $this->x_actual_string;
                        break;
                    case 19:
                        $this->x_result['State'] = $this->x_actual_string;
                        break;
                    case 20:
                        $this->x_result['Zip'] = $this->x_actual_string;
                        break;
                    case 21:
                        $this->x_result['Country'] = $this->x_actual_string;
                        break;
                    case 22:
                        $this->x_result['Phone'] = $this->x_actual_string;
                        break;
                    case 23:
                        $this->x_result['Fax'] = $this->x_actual_string;
                        break;
#12

[eluser]barryskidmore[/eluser]
Code:
case 24:
                        $this->x_result['Email'] = $this->x_actual_string;
                        break;
                    case 25:
                        $this->x_result['ShipFirstName'] = $this->x_actual_string;
                        break;
                    case 26:
                        $this->x_result['ShipLastName'] = $this->x_actual_string;
                        break;
                    case 27:
                        $this->x_result['ShipCompany'] = $this->x_actual_string;
                        break;
                    case 28:
                        $this->x_result['ShipAddress'] = $this->x_actual_string;
                        break;
                    case 29:
                        $this->x_result['ShipCity'] = $this->x_actual_string;
                        break;
                    case 30:
                        $this->x_result['ShipState'] = $this->x_actual_string;
                        break;
                    case 31:
                        $this->x_result['ShipZip'] = $this->x_actual_string;
                        break;
                    case 32:
                        $this->x_result['ShipCountry'] = $this->x_actual_string;
                        break;
                    case 33:
                        $this->x_result['Tax'] = $this->x_actual_string;
                        break;
                    case 34:
                        $this->x_result['Duty'] = $this->x_actual_string;
                        break;
                    case 35:
                        $this->x_result['Freight'] = $this->x_actual_string;
                        break;
                    case 36:
                        $this->x_result['TaxExempt'] = $this->x_actual_string;
                        break;
                    case 37;
                        $this->x_result['PurchaseOrder'] = $this->x_actual_string;
                        break;
                    case 38:
                        $this->x_result['MD5Hash'] = $this->x_actual_string;
                        break;
                    case 39:
                        $this->x_result['CodeResponse'] = $this->x_actual_string;
                        break;
                    default:
                        $this->x_result[$this->x_position] = $this->x_actual_string;;
                        break;
                    
                }
                // Clean up for next pass
                $this->x_response = substr($this->x_response,$this->x_position);
            }
        }
        return $this->x_result;
    }
#13

[eluser]barryskidmore[/eluser]
Code:
function build_transaction($cart_id,$recurring_billing,$last_4) {
        $this->x_cart = $this->chalkboard->Cart_model->display_cart($cart_id);
        $this->x_subtotal = 0;
        $this->x_taxes = 0;
        $this->x_amount = 0;
        $this->x_line_item = '';
        $this->x_invoice_num = $cart_id;
        $this->x_cust_id = $this->chalkboard->session->userdata['user_id'];
        $this->x_customer_ip = $_SERVER["REMOTE_ADDR"];
        $this->x_recurring_billing = $recurring_billing;
        $this->item_counter = 0;
        if ($this->x_cart != 0) {
            foreach ($this->x_cart as $this->x_item) {
                $this->item_price_subtotal = $this->x_item->qty * $this->x_item->price;
                $this->item_tax = $this->x_item->tax_rate / 100;
                $this->item_tax = $this->item_price_subtotal * $this->item_tax;
                $this->item_price_total = $this->item_price_subtotal + $this->item_tax;
                if ($this->item_counter > 0) {
                    $this->x_line_item .= '&x_line_item='.urlencode($this->x_item->invoice_id).'<|>'.urlencode($this->x_item->name).'<|><|>'.urlencode($this->x_item->qty).'<|>'.urlencode($this->x_item->price).'<|>Y';
                } else {
                    $this->x_line_item .= 'x_line_item='.urlencode($this->x_item->invoice_id).'<|>'.urlencode($this->x_item->name).'<|><|>'.urlencode($this->x_item->qty).'<|>'.urlencode($this->x_item->price).'<|>Y';
                }
                $this->x_first_name = $this->x_item->fname;
                $this->x_last_name = $this->x_item->lname;
                $this->x_company = '';
                $this->x_address = $this->x_item->addr1.' '.$this->x_item->addr2;
                $this->x_city = $this->x_item->city;
                $this->x_state = $this->x_item->province;
                $this->x_zip = $this->x_item->postal;
                $this->x_country = $this->x_item->country;
                if ($last_4 == 1) {
                    $this->x_card_num = $this->x_item->last_4;
                    $this->x_trans_id = $this->x_item->transaction_id;
                }
                $this->item_counter++;
            }
            $this->x_subtotal = $this->x_subtotal + $this->item_price_subtotal;
            $this->x_taxes = $this->x_taxes + $this->item_tax;
            $this->x_amount = $this->x_amount + $this->item_price_total;
        }
    }
    
    # Authorizes payment based on current cart information.
    function authorize($cart_id = 0, $recurring_billing = 0) {
        if ($cart_id != 0) {
            $this->x_type = 'AUTH_CAPTURE';
            $this->x_description = 'Humanicity Website Transaction';
            $this->build_transaction($cart_id,0,0);
            return $this->parse_response($this->transact());
        } else {
            return 0;
        }
    }
    
    # Issues a percentage based credit (default 100%) to a transaction
    function credit($cart_id = 0) {
        if ($cart_id != 0) {
            $this->x_type = 'CREDIT';
            $this->x_description = 'Humanicity Website Credit';
            $this->build_transaction($cart_id,0,1);
            return $this->parse_response($this->transact());
        } else {
            return 0;
        }
    }
    
    # Voids a transaction from the system
    function void($cart_id = 0) {
        if ($cart_id != 0) {
            $this->x_type = 'VOID';
            $this->x_description = 'Humanicity Website VOID';
            return $this->parse_response($this->transact());
        } else {
            return 0;
        }
    }
    
}
#14

[eluser]Colin Williams[/eluser]
You know, most merchants (including Authorize.net) already provide tried and true PHP code for interacting with the gateway API. Usually it's just a PHP Class (meaning instant CI library), so why reinvent the wheel? Typically all one needs to do is custom-write the cart/order processing stuff
#15

[eluser]zeedy2k[/eluser]
anyone figured out googlecheckout for CI?
#16

[eluser]Colin Williams[/eluser]
Please refrain from the "for CI" mindset. It's still PHP, and Google provides [url="http://code.google.com/apis/checkout/samples/Google_Checkout_Sample_Code_PHP.html"]a wealth of sample PHP code[/url] for developers.
#17

[eluser]Panchesco[/eluser]
Thanks, Barryskidmore. Good stuff.




Theme © iAndrew 2016 - Forum software by © MyBB