Send plan purchase confirmation

@param Invoice $invoice
@param float   $amount
321549
public function sendAdvertPurchaseConfirmationMessage(Invoice $invoice, $amount)
    {
        //send email to optic to confirm plan purchase
        //check empty bank number account
        $templateName = 'PaymentBundle:Email:advert.confirmation.html.twig';
        $advert = $invoice->getTransaction()->getItems()->first()->getAdvert();
        
        if($invoice->getTransaction()->getActor() instanceof Actor){
            $user = $invoice->getTransaction()->getActor();
        }elseif($invoice->getTransaction()->getOptic() instanceof Optic){
            $user = $invoice->getTransaction()->getOptic();
        }
            
        $toEmail = $user->getEmail();
        $token = null;
            
         $context = array(
            'order_number' => $invoice->getTransaction()->getTransactionKey(),
            'advert' => $advert,
            'user' => $user,
            'token' => $token
        );
        
        $this->sendMessage($templateName, $context, $this->twigGlobal->getParameter('admin_email') , $toEmail);
        
    }
459938
public function showAction(Invoice $invoice, Request $request)
    {
        $buyer = $this->get('security.context')
            ->getToken()
            ->getUser()
            ->getCurrentProfile()
        ;

        // $savedCreditCards = $buyer->getSavedCreditCards();

        return $this->render('HarvestCloudCoreBundle:Buyer/Invoice:show.html.twig', array(
            'invoice' => $invoice,
        ));
    }
500360
public function sendShopownerConfirmation(
        $recipient,
        ApiOrderInterface $apiOrder,
        ContactInterface $customerContact = null
    ) {
        if (!$this->sendEmailConfirmationToShopowner) {
            return false;
        }

        if (empty($recipient)) {
            // fallback address for shop-owner order confirmations
            $recipient = $this->confirmationRecipientEmailAddress;
        }

        return $this->sendConfirmationEmail(
            $recipient,
            $apiOrder,
            $this->templateShopownerConfirmationPath,
            $customerContact
        );
    }
117488
public function settle(IncomingInvoice $invoiceA, IncomingInvoice $invoiceB)
    {
        return $this->connector->settle($invoiceA, $invoiceB);
    }
1248133
protected function triggerInvoiceSendAfter(array $invoice, Source $invoiceSource, Result $result)
    {
        do_action('acumulus_invoice_send_after', $invoice, $invoiceSource, $result);
    }
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'));
    }
1214704
protected function _setPaymentStatus( MShop_Order_Item_Interface $invoice, array $response )
	{
		if( !isset( $response['PAYMENTSTATUS'] ) ) {
			return;
		}

		switch ( $response['PAYMENTSTATUS'] )
		{
			case 'Pending':
				if( isset( $response['PENDINGREASON'] ) )
				{
					if( $response['PENDINGREASON'] === 'authorization' )
					{
						$invoice->setPaymentStatus( MShop_Order_Item_Abstract::PAY_AUTHORIZED );
						break;
					}

					$str = 'PayPal Express: order ID = ' . $invoice->getId() . ', PENDINGREASON = ' . $response['PENDINGREASON'];
					$this->_getContext()->getLogger()->log( $str, MW_Logger_Abstract::INFO );
				}

				$invoice->setPaymentStatus( MShop_Order_Item_Abstract::PAY_PENDING );
				break;

			case 'In-Progress':
				$invoice->setPaymentStatus( MShop_Order_Item_Abstract::PAY_PENDING );
				break;

			case 'Completed':
			case 'Processed':
				$invoice->setPaymentStatus( MShop_Order_Item_Abstract::PAY_RECEIVED );
				break;

			case 'Failed':
			case 'Denied':
			case 'Expired':
				$invoice->setPaymentStatus( MShop_Order_Item_Abstract::PAY_REFUSED );
				break;

			case 'Refunded':
			case 'Partially-Refunded':
			case 'Reversed':
				$invoice->setPaymentStatus( MShop_Order_Item_Abstract::PAY_REFUND );
				break;

			case 'Canceled-Reversal':
			case 'Voided':
				$invoice->setPaymentStatus( MShop_Order_Item_Abstract::PAY_CANCELED );
				break;

			default:
				$str = 'PayPal Express: order ID = ' . $invoice->getId() . ', response = ' . print_r( $response, true );
				$this->_getContext()->getLogger()->log( $str, MW_Logger_Abstract::INFO );
		}
	}
465054
public function setOrderInvoice(\HarvestCloud\CoreBundle\Entity\Invoice\OrderInvoice $invoice = null)
    {
        $this->orderInvoice = $invoice;

        return $this;
    }
354415
public function confirm(string $cardId, string $orderId, int $quantity)
    {
        return $this->httpPostJson('card/pay/confirm', [
            'card_id' => $cardId,
            'order_id' => $orderId,
            'quantity' => $quantity,
        ]);
    }
594160
public function setConfirmationDocflow(\AgentSIB\Diadoc\Api\Proto\Docflow\InvoiceConfirmationDocflow $value = null)
    {
        $this->ConfirmationDocflow = $value;
    }
1226037
public function payWithStripeAction(Invoice $invoice, Request $request)
    {
        $buyer = $this->get('security.context')
            ->getToken()
            ->getUser()
            ->getCurrentProfile()
        ;

        if ($buyer !== $invoice->getCustomer()) {
            throw new NotFoundHttpException('Buyer is not Invoice Customer');
        }

        // First we need to create a payment
        $payment = new InvoicePayment(array($invoice));

        // Save the Payment, so that we get an id
        $em = $this->get('doctrine')->getEntityManager();
        $em->persist($payment);
        $em->flush();

        $this->get('payment.stripe');

        // Grap Stripe token
        $token  = $_POST['stripeToken'];

        try {
            // First create a Stripe customer
            $customer = \Stripe_Customer::create(array(
              'card'        => $token,
              'description' => '#'.$invoice->getCustomer()->getId().' '.$invoice->getCustomer()->getName(),
            ));

            $charge = \Stripe_Charge::create(array(
                'customer'    => $customer->id,
                'amount'      => floor($payment->getAmount()*100),
                'currency'    => 'usd',
                'description' => 'Invoice Payment #'.$payment->getId(),
            )); //, $invoice->getVendor()->getStripeAccessToken());

            // Create SavedCreditCard
            $creditCard = new \HarvestCloud\CoreBundle\Entity\Payment\SavedCreditCard();
            $creditCard->setPaymentServiceKey('stripe');
            $creditCard->setPaymentServiceToken($customer->id);
            $creditCard->setType($charge['card']['type']);
            $creditCard->setExpiryDateFromYearAndMonth($charge['card']['exp_year'], $charge['card']['exp_month']);
            $creditCard->setLastFourDigits($charge['card']['last4']);
            $creditCard->setNameOnCard($charge['card']['name']);

            $invoice->getCustomer()->addSavedCreditCard($creditCard);

            $em->persist($invoice->getCustomer());
            $em->flush();


            // Everything went OK, so let's post the Payment
            $payment->post();

            // Create a Customer
        } catch (\Stripe_CardError $e) {
            // @todo Send some messages back to the browser
            // for now, we'll just re-throw the exception
            throw $e;
        }

        // Save the Payment again after the post()
        $em->persist($payment);
        $em->flush();

        return $this->redirect($this->generateurl('Buyer_invoice_show', array(
            'id' => $invoice->getId(),
        )));
    }
318474
protected function triggerInvoiceCreated(array &$invoice, Source $invoiceSource, Result $localResult)
    {
        /** @noinspection PhpUnhandledExceptionInspection */
        Hook::exec('actionAcumulusInvoiceCreated', array('invoice' => &$invoice, 'source' => $invoiceSource, 'localResult' => $localResult));
    }
303125
public function removeInvoice(\Gpupo\CommonSchema\ORM\Entity\Trading\Order\Shipping\Invoice\Invoice $invoice)
    {
        return $this->invoices->removeElement($invoice);
    }
889327
public function transact($amount, $orderId, $invoiceNumber = null)
    {
        $this->transaction = [
            'amount' => $amount,
            'orderId' => $orderId,
            'invoiceNumber' => $invoiceNumber ?: $orderId,
        ];

        return $this->initiateTransaction();
    }
711523
public function startOneTimeTransaction($amount, $email, $plan = '')
    {
        $oneTimeTransaction = OneTimeTransaction::make(
            $amount,
            $email,
            $plan instanceof Plan ? $plan->get('plan_code') : $plan
        );
        $oneTimeTransaction->setTransactionResource($this->getTransactionResource());
        $transaction = $oneTimeTransaction->initialize();

        if ($transaction instanceof \Exception) {
            throw $transaction;
        }

        return $transaction;
    }
641453
public function registerPayment(PurchaseInvoicePayment $purchaseInvoicePayment)
    {
        if (! isset($purchaseInvoicePayment->payment_date)) {
            throw new ApiException('Required [payment_date] is missing');
        }

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

        $this->connection()->patch($this->endpoint . '/' . $this->id . '/register_payment',
            $purchaseInvoicePayment->jsonWithNamespace()
        );

        return $this;
    }
777750
public function collect(Invoice $invoice)
    {
        parent::collect($invoice);

        $baseInterest = (float) $invoice->getBaseGabrielqsInstallmentsInterestAmount();
        $interest = (float) $invoice->getGabrielqsInstallmentsInterestAmount();
        if ($baseInterest) {
            $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseInterest);
            $invoice->setGrandTotal($invoice->getGrandTotal() + $interest);
        }

        return $this;
    }