Register a payment for the current invoice.

@param SalesInvoicePayment $salesInvoicePayment (payment_date and price are required)
@return $this
@throws ApiException
507103
public function registerPayment(SalesInvoicePayment $salesInvoicePayment)
    {
        if (! isset($salesInvoicePayment->payment_date)) {
            throw new ApiException('Required [payment_date] is missing');
        }

        if (! isset($salesInvoicePayment->price)) {
            throw new ApiException('Required [price] is missing');
        }

        $this->connection()->post($this->endpoint . '/' . $this->id . '/payments',
            $salesInvoicePayment->jsonWithNamespace()
        );

        return $this;
    }
1236594
public function coverInvoice($client, $invoiceId = null)
    {
        return $this->api->coverInvoice($this->getClientId($client), $invoiceId);
    }
1060515
public function create($data, $invoiceId, $invoiceItemId = null)
    {
        if (isset($invoiceItemId)) {
            return $this->client()->put(
                $data,
                'invoices/{invoiceId}/items/{invoiceItemId}',
                ['invoiceId' => $invoiceId, 'invoiceItemId' => $invoiceItemId]
            );
        }

        return $this->client()->post(
                $data,
                'invoices/{invoiceId}/items',
                ['invoiceId' => $invoiceId]
            );
    }
1269147
public function invoice()
    {
        $this->checkAuth();
        $this->checkCartNotEmpty();
        $this->checkValidDelivery();

        $message = false;

        $orderPayment = $this->createForm(FrontForm::ORDER_PAYMENT);

        try {
            $form = $this->validateForm($orderPayment, "post");

            $invoiceAddressId = $form->get("invoice-address")->getData();
            $paymentModuleId = $form->get("payment-module")->getData();

            /* check that the invoice address belongs to the current customer */
            $invoiceAddress = AddressQuery::create()->findPk($invoiceAddressId);
            if ($invoiceAddress->getCustomerId() !== $this->getSecurityContext()->getCustomerUser()->getId()) {
                throw new \Exception(
                    $this->getTranslator()->trans(
                        "Invoice address does not belong to the current customer",
                        [],
                        Front::MESSAGE_DOMAIN
                    )
                );
            }

            $orderEvent = $this->getOrderEvent();
            $orderEvent->setInvoiceAddress($invoiceAddressId);
            $orderEvent->setPaymentModule($paymentModuleId);

            $this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_INVOICE_ADDRESS, $orderEvent);
            $this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_PAYMENT_MODULE, $orderEvent);

            return $this->generateRedirectFromRoute("order.payment.process");

        } catch (FormValidationException $e) {
            $message = $this->getTranslator()->trans(
                "Please check your input: %s",
                ['%s' => $e->getMessage()],
                Front::MESSAGE_DOMAIN
            );
        } catch (PropelException $e) {
            $this->getParserContext()->setGeneralError($e->getMessage());
        } catch (\Exception $e) {
            $message = $this->getTranslator()->trans(
                "Sorry, an error occured: %s",
                ['%s' => $e->getMessage()],
                Front::MESSAGE_DOMAIN
            );
        }

        if ($message !== false) {
            Tlog::getInstance()->error(
                sprintf("Error during order payment process : %s. Exception was %s", $message, $e->getMessage())
            );

            $orderPayment->setErrorMessage($message);

            $this->getParserContext()
                ->addForm($orderPayment)
                ->setGeneralError($message)
            ;
        }

        return $this->generateErrorRedirect($orderPayment);
    }
524603
public function settle(Payable $invoiceA, Payable $invoiceB, $sendEmail = false)
    {
        if ($invoiceA->state != 'open' && $invoiceA->state != 'late') {
            throw new InvalidStateException('Invalid state for invoice '.$invoiceA->id);
        }
        if ($invoiceB->state != 'open' && $invoiceB->state != 'late') {
            throw new InvalidStateException('Invalid state for invoice '.$invoiceB->id);
        }

        $typeA = $this->getType($invoiceA);
        $typeB = $this->getType($invoiceB);
        if ($typeA != $typeB) {
            throw new UnableToSettleException('Unable to settle invoices, types are not equal');
        }
        if (
            ($invoiceA->totalUnpaid > 0 && $invoiceB->totalUnpaid > 0) ||
            ($invoiceA->totalUnpaid < 0 && $invoiceB->totalUnpaid < 0)
        ) {
            throw new UnableToSettleException('Unable to settle invoices, signs are equal');
        }

        $price = min(abs($invoiceA->totalUnpaid), abs($invoiceB->totalUnpaid));

        $paymentClassA = __NAMESPACE__.'\\'.$typeA.'\\Payment';
        $paymentClassB = __NAMESPACE__.'\\'.$typeB.'\\Payment';
        $paymentA = new $paymentClassA(array(
            'paymentDate' => new DateTime(),
            'paymentMethod' => 'credit_invoice',
            'price' => ($invoiceA->totalUnpaid > 0 ? 1 : -1) * $price,
            'sendEmail' => $sendEmail,
        ));
        $paymentB = new $paymentClassB(array(
            'paymentDate' => new DateTime(),
            'paymentMethod' => 'credit_invoice',
            'price' => ($invoiceB->totalUnpaid > 0 ? 1 : -1) * $price,
            'sendEmail' => $sendEmail,
        ));

        $invoiceA->registerPayment($this->getService($typeA), $paymentA);
        $invoiceB->registerPayment($this->getService($typeB), $paymentB);
    }
696567
protected function registerApiClient(ContainerBuilder $containerBuilder, $config)
    {
        $containerBuilder->setAlias('paymentsuite.paylands.api.client', $config['api_client']);

        if (Configuration::API_CLIENT_DEFAULT == $config['api_client']) {
            $this->resolveApiClientInterfaces($containerBuilder, $config['interfaces']);

            $this->registerEndpointServices($containerBuilder, $config['services']);
        }
    }
30600
public function sendPurchaseNotification($invoice)
    {
        $templateName = 'PaymentBundle:Email:sale.notification.admin.html.twig';

        if($invoice->getTransaction()->getItems()->first()->getProduct() instanceof Product){
            $product = $invoice->getTransaction()->getItems()->first()->getProduct();
        }
        
        $sellerEmails = array();
        if($invoice->getTransaction()->getItems()->first()->getProduct()->getActor() instanceof Actor){
            $sellerEmails[] = $invoice->getTransaction()->getItems()->first()->getProduct()->getActor()->getEmail();
        } 
            
        $context = array(
            'order_number'    => $invoice->getTransaction()->getTransactionKey(),
            'invoice_date'      => $invoice->getCreated(),
            'user_email'        => $invoice->getTransaction()->getActor()->getEmail(),
            'seller_email'        => implode(',', $sellerEmails),
            'order_details_url' => $this->router->generate('payment_checkout_showinvoice', array('number' => $invoice->getInvoiceNumber()), UrlGeneratorInterface::ABSOLUTE_URL),
        );

        $this->sendMessage($templateName, $context, $this->twigGlobal->getParameter('admin_email'), $this->twigGlobal->getParameter('admin_email'));
    }
1155051
public function transformFromOrder(OrderInterface $order, InvoiceInterface $invoice)
    {
        $event = new OrderTransformEvent($order);
        $this->eventDispatcher->dispatch(TransformerEvents::PRE_ORDER_TO_INVOICE_TRANSFORM, $event);

        $invoice->setName($order->getBillingName());
        $invoice->setAddress1($order->getBillingAddress1());
        $invoice->setAddress2($order->getBillingAddress2());
        $invoice->setAddress3($order->getBillingAddress3());
        $invoice->setCity($order->getBillingCity());
        $invoice->setCountry($order->getBillingCountryCode());
        $invoice->setPostcode($order->getBillingPostcode());

        $invoice->setEmail($order->getBillingEmail());
        $invoice->setFax($order->getBillingFax());
        $invoice->setMobile($order->getBillingMobile());
        $invoice->setPhone($order->getBillingPhone());
        $invoice->setReference($order->getReference());

        $invoice->setCurrency($order->getCurrency());
        $invoice->setCustomer($order->getCustomer());
        $invoice->setTotalExcl($order->getTotalExcl());
        $invoice->setTotalInc($order->getTotalInc());

        $invoice->setPaymentMethod($order->getPaymentMethod());

        $invoice->setLocale($order->getLocale());

        foreach ($order->getOrderElements() as $orderElement) {
            $invoiceElement = $this->createInvoiceElementFromOrderElement($orderElement);
            $invoiceElement->setInvoice($invoice);
            $invoice->addInvoiceElement($invoiceElement);
        }

        if ($order->getDeliveryCost() > 0) {
            $this->addDelivery($invoice, $order);
        }

        $invoice->setStatus(InvoiceInterface::STATUS_OPEN);

        $event = new InvoiceTransformEvent($invoice);
        $this->eventDispatcher->dispatch(TransformerEvents::POST_ORDER_TO_INVOICE_TRANSFORM, $event);
    }
792865
public function setWithPayer($withPayer = true)
    {
        $this->isBool($withPayer, 'withPayer');
        $this->withPayer = $withPayer;

        if ($withPayer === false) {
            $this->payerLine1 = '';
            $this->payerLine2 = '';
            $this->payerLine3 = '';
            $this->payerLine4 = '';
        }

        return $this;
    }
911997
public function registerPayment(Payable $invoice, AbstractPayment $payment)
    {
        $classname = $this->getType($invoice);

        if (intval($invoice->getId()) == 0) {
            $invoice->save($this->getService($classname));
        }
        $idProperty = strtolower($classname) . 'Id';
        $payment->setData(array(
            $idProperty => $invoice->getId()
        ));

        $response = $this->request(
            $this->buildUrl($invoice, null, '/payments'), 'POST', $this->mapper->mapToStorage($payment)
        );

        return $this->mapper->mapFromStorage($response);
    }
642527
public function addCurrentInvoiceToPayment(Varien_Event_Observer $observer)
    {
        $invoice = $observer->getInvoice();
        $payment = $observer->getPayment();
        $payment->setCurrentInvoice($invoice);

        return $this;
    }
1350294
public function doExpressCheckoutPayment($data, $token, $payerid)
    {
        $this->setItemSubTotal($data);

        $this->post = $this->setCartItems($data['items'])->merge([
            'TOKEN'                          => $token,
            'PAYERID'                        => $payerid,
            'PAYMENTREQUEST_0_ITEMAMT'       => $this->subtotal,
            'PAYMENTREQUEST_0_AMT'           => $data['total'],
            'PAYMENTREQUEST_0_PAYMENTACTION' => !empty($this->config['payment_action']) ? $this->config['payment_action'] : 'Sale',
            'PAYMENTREQUEST_0_CURRENCYCODE'  => $this->currency,
            'PAYMENTREQUEST_0_DESC'          => $data['invoice_description'],
            'PAYMENTREQUEST_0_INVNUM'        => $data['invoice_id'],
            'PAYMENTREQUEST_0_NOTIFYURL'     => $this->notifyUrl,
        ]);

        $this->setShippingAmount($data);

        return $this->doPayPalRequest('DoExpressCheckoutPayment');
    }
599747
public function addPayment(\OxidEsales\PayPalModule\Model\OrderPayment $payment)
    {
        //order payment info
        if ($this->getOrderId()) {
            $payment->setOrderId($this->getOrderId());
            $payment->save();
        }

        $this->load($this->getOrderId());

        return $payment;
    }
1249756
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;
    }
1144921
public function charge(InvoicePayment $payment)
    {
        // Make a charge through Stripe
        try {
            $charge = Charge::create([
                // Multiply by 100 as Stripe charges in pence.
                'amount' => $payment->amount * 100,
                'currency' => 'gbp',
                'description' => 'Invoice payment',
                'metadata' => [
                    'invoice_id' => $payment->invoice->id
                ],
                'source' => $payment->getPreCommitMetadataArray()['STRIPE_TOKEN'],
            ]);

            // Add Stripe payment ID to invoice payment
            $payment->payment_id = $charge->id;

            $responseMeta = new InvoicePaymentMetadata();
            $responseMeta->key = 'GATEWAY_RESPONSE';
            $responseMeta->value = $charge->status;
            $payment->metadata()->save($responseMeta);

            $payment->save();

            return true;

        } catch(Card $cardError) {

            $payment->payment_id = $cardError->getJsonBody()['error']['charge'];
            $responseMeta = new InvoicePaymentMetadata();
            $responseMeta->key = 'GATEWAY_RESPONSE';
            $responseMeta->value = $cardError->getMessage();
            $payment->metadata()->save($responseMeta);
            $payment->save();

            return false;
        }
    }
637748
@Indexable(type = IndexableType.REINDEX)
	@Override
	public CommerceOrderPayment addCommerceOrderPayment(
		CommerceOrderPayment commerceOrderPayment) {
		commerceOrderPayment.setNew(true);

		return commerceOrderPaymentPersistence.update(commerceOrderPayment);
	}
1284221
private function addInvoice($trans, $invoice_no, $ref_no, $options)
    {
        $trans->addChild('InvoiceNo', $invoice_no);
        $trans->addChild('RefNo', $ref_no ?: $invoice_no);
        if ($options['merchant']) {
            $trans->addChild('OperatorID', $options['merchant']);
        }
        if ($options['description']) {
            $trans->addChild('Memo', $options['description']);
        }
    }