public function pay($amount, $parameters) {
        $payment = new InvoicePayment();
        $payment->amount = $amount;

        $payment->setPreCommitMetadataArray($parameters['metadata']);

        $payment->invoice()->associate($this);
        $payment->type()->associate($parameters['type']);

        if(isset($parameters['id'])) {
            $payment->payment_id = $parameters['id'];
        }

        $payment->save();
        return $payment;
    }