Passing multiple values to credit card debit

319 Views Asked by At

I am trying to pass three values to debit transaction in balanced payments using PHP.

I am able to create a transaction successfully when I do this:

$transaction=$customer->debit($total*100);

as opposed to defining $transaction as an array. When I create the array below I get an error. I have reviewed the API docs but there is no example with multiple values being passed in PHP.

function new_transaction($cc_token=NULL, $total=NULL, $order_id=NULL){ 

    $customer = \Balanced\Customer::get('/v1/customers/CU7MPeEt3DhflopxaeFG');
    $transaction=$customer->debit(array(
        "amount"        => $total*100,
        "source_uri"    => $cc_token,
        "appears_on_statement_as" => 'Order #'.$order_id,
    ));     

    return $transaction->uri;

}

Sorry I didn't think to post the error since it is opaque - here it is:

Fatal error: Uncaught exception 'Balanced\Errors\Error' in /Applications/MAMP/htdocs/merchantfuse/application/libraries/balanced/balanced/src/Balanced/Errors.php:35 Stack trace: #0 /Applications/MAMP/htdocs/merchantfuse/application/libraries/balanced/balanced/src/Balanced/Resource.php(24): Balanced\Errors\Error::createFromResponse(Object(Httpful\Response)) #1 [internal function]: Balanced\Resource::convertError(Object(Httpful\Response)) #2 /Applications/MAMP/htdocs/merchantfuse/application/libraries/balanced/restful/src/RESTful/Client.php(69): call_user_func('Balanced\Resour...', Object(Httpful\Response)) #3 /Applications/MAMP/htdocs/merchantfuse/application/libraries/balanced/restful/src/RESTful/Client.php(34): RESTful\Client->_op(Object(Httpful\Request)) #4 /Applications/MAMP/htdocs/merchantfuse/application/libraries/balanced/restful/src/RESTful/Collection.php(35): RESTful\Client->post('/v1/customers/C...', Array) #5 /Applications/MAMP/htdocs/merchantfuse/application/libraries/balanced/balanced/src/Balanced/Customer.php in /Applications/MAMP/htdocs/merchantfuse/application/libraries/balanced/balanced/src/Balanced/Errors.php on line 35

1

There are 1 best solutions below

0
On BEST ANSWER

With the help of Balanced Support I figured this out

function new_transaction($cc_token=NULL, $total=NULL, $order_id=NULL){  
        $customer = \Balanced\Customer::get('/v1/customers/CU7guBPfer2uEkOEopU0KgXl');
        $transaction=$customer->debit($total*100, 'Statement Info', null, 'Description, $cc_token, null);       

        return $transaction->uri;
    }

works...check out the function in the balanced code: https://github.com/balanced/balanced-php/blob/master/src/Balanced/Customer.php#L141