Create transaction or Invoice with API


#1

Hi there,

I have a web form written in PHP adding users to Splynx, at the time of filling out the web form we take a payment.

I would like to have this payment and invoice created automatically inside Splynx and I am wondering how to achieve this with the API.

I have previously successfully created payments using the API as per Trouble creating payment with API

However I would like to do the following:
Have an invoice be generated and instantly paid (out of credit in splynx is ok because I can use API to generate a payment for the invoice value)

I am not sure what order I should do things in:
Eg. do I need to create a transaction at all? or is it enough to make a payment first for the invoice amount and then generate an invoice to be automatically paid from remaining credit?

If you could please provide some example of the API syntax for invoice and/or transaction that would be very helpful.

thanks


#2

Solved this myself, transactions happen automatically and all I needed to do was first create a payment then create an invoice to be automatically paid from it.

PHP code as such:

//start create payment

print "Create Payment\n";
$result = $api->api_call_post($PaymentsApiUrl,
    array(
        'customer_id' => $CustomerId,
        'payment_type' => '9',
        'date' => substr($date, 0, -9),
        'amount' => $total,
        'comment' => 'Paid by Stripe',
        'field_1' => $GLOBALS['stripeid'],

    ));

print "Result: ";
if ($result) {
    print "Ok!\n";
    print_r($api->response);
    $PaymentId = $api->response['id'];
} else {
    print "Fail! Error code: $api->response_code\n";
    print_r($api->response);
    $PaymentId = false;

}
print "\n-------------------------------------------------\n";


//end create payment


//start create invoice

print "Create Invoice\n";
$result = $api->api_call_post($InvoiceApiUrl,
    array(
        'customer_id' => $CustomerId,
        'date_created' => substr($date, 0, -9),
        'payd_from_deposit' => '1',
        'status' => 'paid',
        'items' => array(
            array( 
            'description' => 'Installation booking fee (includes modem)',
            'quantity' => 1,
            'unit' => 1,
            'price' => ($total / 1.1),
            'tax' => 10,
            )
      )

    ));

print "Result: ";
if ($result) {
    print "Ok!\n";
    print_r($api->response);
    $InvoiceId = $api->response['id'];
} else {
    print "Fail! Error code: $api->response_code\n";
    print_r($api->response);
    $InvoiceId = false;

}
print "\n-------------------------------------------------\n";