From 617a0518112cc47c2ef230623f0e1d87023a1ab6 Mon Sep 17 00:00:00 2001 From: Tejpal Singh Date: Fri, 13 Jan 2023 15:42:52 +0530 Subject: [PATCH 01/40] .env.dist file updated for tax split changes --- .env.dist | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.env.dist b/.env.dist index c7e545c7..55f6f5fb 100644 --- a/.env.dist +++ b/.env.dist @@ -145,3 +145,10 @@ MAILER_DSN=smtp://null # we will wait at least that duration between two notification emails. Default to 10 minutes. # 0 to disable throttling, can go as high as the notification worker max life, i.e. 3600 by default. #MAIL_ON_NOTIFICATION_ENDPOINT_DOWN_COOLDOWN=10 + +# Enable the tax split from order total +# Tax amount will be credited to merchants stripe connected account dedicated for taxes +# Update & uncomment below two lines (STRIPE_TAX_ACCOUNT and TAX_ORDER_POSTFIX) & make sure value of TAX_ORDER_POSTFIX must not +# be blank in case if this line is uncommented +#STRIPE_TAX_ACCOUNT=acct_xxxxxxxxxxxxxxx +#TAX_ORDER_POSTFIX=_XXX \ No newline at end of file From 34a0d44e1e14ed1ababb0697b2799c4458fb0098 Mon Sep 17 00:00:00 2001 From: Tejpal Singh Date: Wed, 18 Jan 2023 12:53:45 +0530 Subject: [PATCH 02/40] tax split changes --- src/Command/SellerSettlementCommand.php | 6 +-- src/Entity/MiraklOrder.php | 2 + src/Entity/MiraklProductOrder.php | 50 ++++++++++++++++++++ src/Entity/MiraklServiceOrder.php | 48 +++++++++++++++++++ src/Factory/StripePayoutFactory.php | 29 ++++++++++-- src/Factory/StripeTransferFactory.php | 61 +++++++++++++++++++++++-- src/Service/MiraklClient.php | 17 +++++++ src/Service/PaymentRefundService.php | 20 ++++++-- src/Service/PaymentSplitService.php | 25 ++++++++-- src/Service/SellerSettlementService.php | 11 +++-- 10 files changed, 243 insertions(+), 26 deletions(-) diff --git a/src/Command/SellerSettlementCommand.php b/src/Command/SellerSettlementCommand.php index 9f237a03..0a7375b9 100644 --- a/src/Command/SellerSettlementCommand.php +++ b/src/Command/SellerSettlementCommand.php @@ -91,7 +91,7 @@ private function processProvidedShopId(int $shopId) ); $this->dispatchPayouts( - $this->sellerSettlementService->getPayoutsFromInvoices($invoices) + $this->sellerSettlementService->getPayoutsFromInvoices($invoices,$this->miraklClient) ); } @@ -114,7 +114,7 @@ private function processBacklog() $this->dispatchTransfers($transfersByInvoiceId); $payouts = $this->sellerSettlementService - ->updatePayoutsFromInvoices($retriablePayouts, $invoices); + ->updatePayoutsFromInvoices($retriablePayouts, $invoices,$this->miraklClient); $this->dispatchPayouts($payouts); } @@ -151,7 +151,7 @@ private function processNewInvoices() ); $this->dispatchPayouts( - $this->sellerSettlementService->getPayoutsFromInvoices($invoices) + $this->sellerSettlementService->getPayoutsFromInvoices($invoices,$this->miraklClient) ); $checkpoint = $this->updateCheckpoint($invoices, $checkpoint); diff --git a/src/Entity/MiraklOrder.php b/src/Entity/MiraklOrder.php index 8b823387..c31d9f97 100644 --- a/src/Entity/MiraklOrder.php +++ b/src/Entity/MiraklOrder.php @@ -37,5 +37,7 @@ abstract public function getAmountDue(): float; abstract public function getAbortedAmount(): float; abstract public function getOperatorCommission(): float; abstract public function getRefundedOperatorCommission(StripeRefund $refund): float; + abstract public function getRefundedTax(StripeRefund $refund): float; abstract public function getCurrency(): string; + abstract public function getOrderTaxTotal(): float; } diff --git a/src/Entity/MiraklProductOrder.php b/src/Entity/MiraklProductOrder.php index a8d7bc22..882cf665 100644 --- a/src/Entity/MiraklProductOrder.php +++ b/src/Entity/MiraklProductOrder.php @@ -122,6 +122,35 @@ public function getRefundedOperatorCommission(StripeRefund $refund): float return 0; } + + + public function getRefundedTax(StripeRefund $refund): float + { + foreach ($this->getOrderLines() as $line) { + if ($refund->getMiraklOrderLineId() === $line['order_line_id']) { + foreach ($line['refunds'] as $orderRefund) { + if ($refund->getMiraklRefundId() === $orderRefund['id']) { + $tax = $this->getRefundLineTaxes($orderRefund); + return $tax;//$orderRefund['commission_total_amount']; + } + } + } + } + + return 0; + } + + protected function getRefundLineTaxes(array $refundLine): float + { + $taxes = 0; + $allTaxes = array_merge($refundLine['shipping_taxes'] ?? [], $refundLine['taxes'] ?? []); + foreach ($allTaxes as $tax) { + $taxes += (float) $tax['amount']; + } + + return $taxes; + } + public function getCurrency(): string { @@ -156,4 +185,25 @@ protected function getOrderLineCanceledAmountWithTaxes(array $canceledOrderLines return $canceledAmount; } + + public function getOrderTaxTotal(): float + { + $amount = 0; + foreach ($this->getOrderLines() as $orderLine) { + if (!in_array($orderLine['order_line_state'], ['REFUSED', 'CANCELED'])) { + $amount += $this->getOrderLineOrderTaxes($orderLine); + } + } + return $amount; + } + + protected function getOrderLineOrderTaxes(array $orderLine): float + { + $taxes = 0; + $allTaxes = $orderLine['taxes'] ?? []; + foreach ($allTaxes as $tax) { + $taxes += (float) $tax['amount']; + } + return $taxes; + } } diff --git a/src/Entity/MiraklServiceOrder.php b/src/Entity/MiraklServiceOrder.php index 90534bcc..37456d38 100644 --- a/src/Entity/MiraklServiceOrder.php +++ b/src/Entity/MiraklServiceOrder.php @@ -108,9 +108,57 @@ public function getRefundedOperatorCommission(StripeRefund $refund): float return 0; } + + public function getRefundedTax(StripeRefund $refund): float + { + + foreach ($this->order['refunds'] as $orderRefund) { + if ($refund->getMiraklRefundId() === $orderRefund['id']) { + if ($refund->getMiraklRefundId() === $orderRefund['id']) { + return $this->getRefundLineTaxes($orderRefund);//$orderRefund['commission_total_amount']; + } + } + } + + return 0; + } + + protected function getRefundLineTaxes(array $refundLine): float + { + $taxes = 0; + $allTaxes = array_merge($refundLine['shipping_taxes'] ?? [], $refundLine['taxes'] ?? []); + foreach ($allTaxes as $tax) { + $taxes += (float) $tax['amount']; + } + + + return $taxes; + } public function getCurrency(): string { return $this->order['currency_code']; } + + public function getOrderTaxTotal(): float + { + $taxes = 0; + + if (!$this->isTaxIncluded()) { + foreach (($this->order['price']['taxes'] ?? []) as $tax) { + $taxes += (float) $tax['amount']; + } + } + return $taxes; + } + + protected function getOrderLineOrderTaxes(array $orderLine): float + { + $taxes = 0; + $allTaxes = $orderLine['taxes'] ?? []; + foreach ($allTaxes as $tax) { + $taxes += (float) $tax['amount']; + } + return $taxes; + } } diff --git a/src/Factory/StripePayoutFactory.php b/src/Factory/StripePayoutFactory.php index a5701436..e175f0dd 100644 --- a/src/Factory/StripePayoutFactory.php +++ b/src/Factory/StripePayoutFactory.php @@ -18,6 +18,10 @@ class StripePayoutFactory implements LoggerAwareInterface * @var AccountMappingRepository */ private $accountMappingRepository; + + /** + * @var MiraklClient + */ public function __construct( AccountMappingRepository $accountMappingRepository @@ -29,7 +33,7 @@ public function __construct( * @param array $invoice * @return StripePayout */ - public function createFromInvoice(array $invoice): StripePayout + public function createFromInvoice(array $invoice,MiraklClient $mclient): StripePayout { $payout = new StripePayout(); $payout->setMiraklInvoiceId($invoice['invoice_id']); @@ -37,7 +41,7 @@ public function createFromInvoice(array $invoice): StripePayout MiraklClient::getDatetimeFromString($invoice['date_created']) ); - return $this->updateFromInvoice($payout, $invoice); + return $this->updateFromInvoice($payout, $invoice,$mclient); } /** @@ -45,7 +49,7 @@ public function createFromInvoice(array $invoice): StripePayout * @param array $invoice * @return StripePayout */ - public function updateFromInvoice(StripePayout $payout, array $invoice): StripePayout + public function updateFromInvoice(StripePayout $payout, array $invoice,MiraklClient $mclient): StripePayout { // Payout already created if ($payout->getPayoutId()) { @@ -54,7 +58,7 @@ public function updateFromInvoice(StripePayout $payout, array $invoice): StripeP // Amount and currency try { - $payout->setAmount($this->getInvoiceAmount($invoice)); + $payout->setAmount($this->getInvoiceAmount($invoice,$mclient)); $payout->setCurrency(strtolower($invoice['currency_iso_code'])); } catch (InvalidArgumentException $e) { return $this->abortPayout($payout, $e->getMessage()); @@ -118,9 +122,13 @@ private function getAccountMapping(int $shopId): AccountMapping * @param array $invoice * @return int */ - private function getInvoiceAmount(array $invoice): int + private function getInvoiceAmount(array $invoice,MiraklClient $mclient ): int { $amount = $invoice['summary']['amount_transferred'] ?? 0; + $transactions = $mclient->getTransactionsForInvoce($invoice['invoice_id']); + + $total_tax = $this->findTotalOrderTax($transactions); + $amount = $amount - $total_tax; $amount = gmp_intval((string) ($amount * 100)); if ($amount <= 0) { throw new InvalidArgumentException(sprintf( @@ -178,4 +186,15 @@ private function markPayoutAsCreated(StripePayout $payout): StripePayout $payout->setStatusReason(null); return $payout->setStatus(StripePayout::PAYOUT_CREATED); } + + private function findTotalOrderTax($transactions) { + $taxes=0; + foreach ($transactions as $trx) { + if($trx['type']=='ORDER_AMOUNT_TAX'){ + $taxes += (float) $trx['amount']; + } + } + return $taxes; + + } } diff --git a/src/Factory/StripeTransferFactory.php b/src/Factory/StripeTransferFactory.php index a987ad09..a5e48093 100644 --- a/src/Factory/StripeTransferFactory.php +++ b/src/Factory/StripeTransferFactory.php @@ -91,13 +91,29 @@ public function createFromOrder(MiraklOrder $order, MiraklPendingDebit $pendingD return $this->updateFromOrder($transfer, $order, $pendingDebit); } + + public function createFromOrderForTax(MiraklOrder $order, MiraklPendingDebit $pendingDebit = null): StripeTransfer + { + if (is_a($order, MiraklServiceOrder::class)) { + $type = StripeTransfer::TRANSFER_SERVICE_ORDER; + } else { + $type = StripeTransfer::TRANSFER_PRODUCT_ORDER; + } + + $transfer = new StripeTransfer(); + $transfer->setType($type); + $transfer->setMiraklId($order->getId().$_ENV['TAX_ORDER_POSTFIX']); + $transfer->setMiraklCreatedDate($order->getCreationDateAsDateTime()); + + return $this->updateFromOrder($transfer, $order, $pendingDebit,true); + } /** * @param StripeTransfer $transfer * @param MiraklOrder $order * @return StripeTransfer */ - public function updateFromOrder(StripeTransfer $transfer, MiraklOrder $order, MiraklPendingDebit $pendingDebit = null): StripeTransfer + public function updateFromOrder(StripeTransfer $transfer, MiraklOrder $order, MiraklPendingDebit $pendingDebit = null, $isForTax = false): StripeTransfer { // Transfer already created if ($transfer->getTransferId()) { @@ -106,7 +122,13 @@ public function updateFromOrder(StripeTransfer $transfer, MiraklOrder $order, Mi // Shop must have a Stripe account try { - $accountMapping = $this->getAccountMapping($order->getShopId()); + if(!$isForTax){ + $accountMapping = $this->getAccountMapping($order->getShopId()); + } + else + { + $accountMapping = $this->accountMappingRepository->findOneByStripeAccountId($_ENV['STRIPE_TAX_ACCOUNT']); + } $transfer->setAccountMapping($accountMapping); } catch (InvalidArgumentException $e) { // Onboarding still to be completed, let's wait @@ -196,6 +218,11 @@ public function updateFromOrder(StripeTransfer $transfer, MiraklOrder $order, Mi $amount = $order->getAmountDue(); $commission = $order->getOperatorCommission(); $transferAmount = $amount - $commission; + $orderTaxTotal = $order->getOrderTaxTotal(); + $transferAmount = $transferAmount - $orderTaxTotal; + if($isForTax){ + $transferAmount = $orderTaxTotal; + } if ($transferAmount <= 0) { return $this->abortTransfer($transfer, sprintf( StripeTransfer::TRANSFER_STATUS_REASON_INVALID_AMOUNT, @@ -222,12 +249,21 @@ public function createFromOrderRefund(MiraklPendingRefund $orderRefund): StripeT return $this->updateOrderRefundTransfer($transfer); } + + public function createFromOrderRefundForTax(MiraklPendingRefund $orderRefund): StripeTransfer + { + $transfer = new StripeTransfer(); + $transfer->setType(StripeTransfer::TRANSFER_REFUND); + $transfer->setMiraklId($orderRefund->getId().$_ENV['TAX_ORDER_POSTFIX']); + + return $this->updateOrderRefundTransfer($transfer,true); + } /** * @param StripeTransfer $transfer * @return StripeTransfer */ - public function updateOrderRefundTransfer(StripeTransfer $transfer): StripeTransfer + public function updateOrderRefundTransfer(StripeTransfer $transfer, $isForTax = false): StripeTransfer { // Transfer already reversed if ($transfer->getTransferId()) { @@ -237,10 +273,13 @@ public function updateOrderRefundTransfer(StripeTransfer $transfer): StripeTrans // Check corresponding StripeRefund $refund = null; try { - $refund = $this->findRefundFromRefundId($transfer->getMiraklId()); + $refund = $this->findRefundFromRefundId(str_replace($_ENV['TAX_ORDER_POSTFIX'],"",$transfer->getMiraklId())); // Fetch transfer to be reversed $orderIds = [$refund->getMiraklOrderId()]; + if($isForTax) + $orderIds = [$refund->getMiraklOrderId().$_ENV['TAX_ORDER_POSTFIX']]; + $orderTransfer = current($this->stripeTransferRepository->findTransfersByOrderIds($orderIds)); // Check order transfer status @@ -265,9 +304,21 @@ public function updateOrderRefundTransfer(StripeTransfer $transfer): StripeTrans } // Amount and currency + $transferAmount = $refund->getAmount(); + $commission = $order->getRefundedOperatorCommission($refund); $commission = gmp_intval((string) ($commission * 100)); - $transfer->setAmount($refund->getAmount() - $commission); + + $refundedTax = $order->getRefundedTax($refund); + $refundedTax = gmp_intval((string) ($refundedTax * 100)); + + $transferAmount = $transferAmount - $commission - $refundedTax; + + + if($isForTax) + $transferAmount = $refundedTax; + + $transfer->setAmount($transferAmount); $transfer->setCurrency(strtolower($order->getCurrency())); } catch (InvalidArgumentException $e) { switch ($e->getCode()) { diff --git a/src/Service/MiraklClient.php b/src/Service/MiraklClient.php index ddace1d3..f0819ce6 100644 --- a/src/Service/MiraklClient.php +++ b/src/Service/MiraklClient.php @@ -172,6 +172,7 @@ public function listProductOrdersByDate(string $datetime) // OR11 by order_id public function listProductOrdersById(array $orderIds) { + $orderIds = array_map(array($this, 'removeTaxKeword'),$orderIds); $res = []; foreach (array_chunk($orderIds, 100) as $chunk) { $res = array_merge($res, $this->paginateByOffset('/api/orders', ['order_ids' => implode(',', $chunk)], 'orders')); @@ -255,6 +256,7 @@ public function listServiceOrdersByDate(string $datetime) // SOR11 by order_id public function listServiceOrdersById(array $orderIds) { + $orderIds = array_map(array($this, 'removeTaxKeword'),$orderIds); $res = $this->paginateByPage('/api/mms/orders', ['order_id' => $orderIds], 'data'); $res = $this->arraysToObjects($res, MiraklServiceOrder::class); return $this->objectsToMap($res, 'getId'); @@ -279,6 +281,7 @@ public function listServicePendingDebits() // SPA11 by order ID public function listServicePendingDebitsByOrderIds(array $orderIds) { + $orderIds = array_map(array($this, 'removeTaxKeword'),$orderIds); $res = $this->paginateByPage('/api/mms/debits', ['order_id' => $orderIds], 'data'); $res = $this->arraysToObjects($res, MiraklServicePendingDebit::class); return $this->objectsToMap($res, 'getOrderId'); @@ -366,6 +369,16 @@ public function updateShopKycStatus(int $shopId, string $status) 'kyc' => ['status' => $status] ]]]); } + + + public function getTransactionsForInvoce(string $invoiceId) + { + $params['accounting_document_number'] = $invoiceId; + $response = $this->get('/api/sellerpayment/transactions_logs', array_merge(['max' => 100], $params)); + $objects = $this->parseResponse($response, 'data'); + $res_map =$this->arraysToMap($objects, 'id'); + return $res_map; + } // parse a date based on the format used by Mirakl public static function getDatetimeFromString(string $date): \DateTimeInterface @@ -378,4 +391,8 @@ public static function getStringFromDatetime(\DateTimeInterface $date): string { return $date->format(self::DATE_FORMAT); } + + private function removeTaxKeword($val) { + return str_replace($_ENV['TAX_ORDER_POSTFIX'],"",$val); + } } diff --git a/src/Service/PaymentRefundService.php b/src/Service/PaymentRefundService.php index 339d6480..1a9497cb 100644 --- a/src/Service/PaymentRefundService.php +++ b/src/Service/PaymentRefundService.php @@ -106,14 +106,22 @@ public function getTransfersFromOrderRefunds(array $orderRefunds): array } $transfer = $this->stripeTransferFactory->updateOrderRefundTransfer($transfer); + $transfer_tax = $this->stripeTransferFactory->updateOrderRefundTransfer($transfer,true); + $transfers[]=$transfer_tax; + } else { // Create new transfer $transfer = $this->stripeTransferFactory->createFromOrderRefund($orderRefund); - + $transfer_tax = $this->stripeTransferFactory->createFromOrderRefundForTax($orderRefund); + $this->stripeTransferRepository->persist($transfer); + $this->stripeTransferRepository->persist($transfer_tax); + $transfers[]=$transfer_tax; + } - + $transfers[] = $transfer; + } // Save @@ -130,7 +138,13 @@ public function updateTransfers(array $transfers): array { $updated = []; foreach ($transfers as $refundId => $transfer) { - $updated[$refundId] = $this->stripeTransferFactory->updateOrderRefundTransfer($transfer); + + if(strpos($refundId, $_ENV['TAX_ORDER_POSTFIX']) !== false){ + + $updated[$refundId] = $this->stripeTransferFactory->updateOrderRefundTransfer($transfer,true); + } + else + $updated[$refundId] = $this->stripeTransferFactory->updateOrderRefundTransfer($transfer); } // Save diff --git a/src/Service/PaymentSplitService.php b/src/Service/PaymentSplitService.php index bd728b18..7075d85a 100644 --- a/src/Service/PaymentSplitService.php +++ b/src/Service/PaymentSplitService.php @@ -66,9 +66,12 @@ public function getTransfersFromOrders(array $orders, array $pendingDebits): arr // Create new transfer $transfer = $this->stripeTransferFactory->createFromOrder($order, $pendingDebit); $this->stripeTransferRepository->persist($transfer); + $tax_transfer = $this->stripeTransferFactory->createFromOrderForTax($order, $pendingDebit); + $this->stripeTransferRepository->persist($tax_transfer); } $transfers[] = $transfer; + if(isset($tax_transfer)) $transfers[] = $tax_transfer; } // Save @@ -87,11 +90,23 @@ public function updateTransfersFromOrders(array $existingTransfers, array $order $updated = []; foreach ($existingTransfers as $orderId => $transfer) { $pendingDebit = $pendingDebits[$orderId] ?? null; - $updated[$orderId] = $this->stripeTransferFactory->updateFromOrder( - $transfer, - $orders[$orderId], - $pendingDebit - ); + if(strpos($orderId, $_ENV['TAX_ORDER_POSTFIX']) !== false){ + $tax_suffixed_orderId= $orderId; + $orderId = str_replace($_ENV['TAX_ORDER_POSTFIX'],"",$orderId); + $pendingDebit = $pendingDebits[$orderId] ?? null; + $updated[$tax_suffixed_orderId] = $this->stripeTransferFactory->updateFromOrder( + $transfer, + $orders[$orderId], + $pendingDebit, + true + ); + }else{ + $updated[$orderId] = $this->stripeTransferFactory->updateFromOrder( + $transfer, + $orders[$orderId], + $pendingDebit + ); + } } // Save diff --git a/src/Service/SellerSettlementService.php b/src/Service/SellerSettlementService.php index 80ba0b4e..732e24ba 100644 --- a/src/Service/SellerSettlementService.php +++ b/src/Service/SellerSettlementService.php @@ -136,7 +136,7 @@ public function getRetriablePayouts(): array * @param array $invoices * @return array StripePayout[] */ - public function getPayoutsFromInvoices(array $invoices): array + public function getPayoutsFromInvoices(array $invoices,MiraklClient $mclient): array { // Retrieve existing StripeTransfers with provided invoice IDs $existingPayouts = $this->stripePayoutRepository @@ -153,11 +153,11 @@ public function getPayoutsFromInvoices(array $invoices): array // Use existing payout $payout = $this->stripePayoutFactory - ->updateFromInvoice($payout, $invoice); + ->updateFromInvoice($payout, $invoice,$mclient); } else { // Create new payout $payout = $this->stripePayoutFactory - ->createFromInvoice($invoice); + ->createFromInvoice($invoice,$mclient); $this->stripePayoutRepository->persist($payout); } @@ -175,13 +175,14 @@ public function getPayoutsFromInvoices(array $invoices): array * @param array $invoices * @return array StripePayout[] */ - public function updatePayoutsFromInvoices(array $existingPayouts, array $invoices) + public function updatePayoutsFromInvoices(array $existingPayouts, array $invoices,MiraklClient $mclient) { $updated = []; foreach ($existingPayouts as $invoiceId => $payout) { $updated[$invoiceId] = $this->stripePayoutFactory->updateFromInvoice( $payout, - $invoices[$invoiceId] + $invoices[$invoiceId], + $mclient ); } From f3b759af5114cfb4750898c2641f0500bbe20108 Mon Sep 17 00:00:00 2001 From: millin-stripe <87815854+millin-stripe@users.noreply.github.com> Date: Wed, 18 Jan 2023 09:59:47 -0500 Subject: [PATCH 03/40] Update to add spaces to calls. Lines Impacted 139, 156, 160, 178, --- src/Service/SellerSettlementService.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Service/SellerSettlementService.php b/src/Service/SellerSettlementService.php index 732e24ba..245450f3 100644 --- a/src/Service/SellerSettlementService.php +++ b/src/Service/SellerSettlementService.php @@ -136,7 +136,7 @@ public function getRetriablePayouts(): array * @param array $invoices * @return array StripePayout[] */ - public function getPayoutsFromInvoices(array $invoices,MiraklClient $mclient): array + public function getPayoutsFromInvoices(array $invoices, MiraklClient $mclient): array { // Retrieve existing StripeTransfers with provided invoice IDs $existingPayouts = $this->stripePayoutRepository @@ -153,11 +153,11 @@ public function getPayoutsFromInvoices(array $invoices,MiraklClient $mclient): a // Use existing payout $payout = $this->stripePayoutFactory - ->updateFromInvoice($payout, $invoice,$mclient); + ->updateFromInvoice($payout, $invoice, $mclient); } else { // Create new payout $payout = $this->stripePayoutFactory - ->createFromInvoice($invoice,$mclient); + ->createFromInvoice($invoice, $mclient); $this->stripePayoutRepository->persist($payout); } @@ -175,7 +175,7 @@ public function getPayoutsFromInvoices(array $invoices,MiraklClient $mclient): a * @param array $invoices * @return array StripePayout[] */ - public function updatePayoutsFromInvoices(array $existingPayouts, array $invoices,MiraklClient $mclient) + public function updatePayoutsFromInvoices(array $existingPayouts, array $invoices, MiraklClient $mclient) { $updated = []; foreach ($existingPayouts as $invoiceId => $payout) { From 6c12a95213c28f12ce42af5b33b55e78a1d9441d Mon Sep 17 00:00:00 2001 From: millin-stripe <87815854+millin-stripe@users.noreply.github.com> Date: Wed, 18 Jan 2023 10:03:29 -0500 Subject: [PATCH 04/40] Compliant Code Changes with spaces and white space --- src/Service/PaymentRefundService.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Service/PaymentRefundService.php b/src/Service/PaymentRefundService.php index 1a9497cb..30d712e9 100644 --- a/src/Service/PaymentRefundService.php +++ b/src/Service/PaymentRefundService.php @@ -106,17 +106,17 @@ public function getTransfersFromOrderRefunds(array $orderRefunds): array } $transfer = $this->stripeTransferFactory->updateOrderRefundTransfer($transfer); - $transfer_tax = $this->stripeTransferFactory->updateOrderRefundTransfer($transfer,true); - $transfers[]=$transfer_tax; + $transfer_tax = $this->stripeTransferFactory->updateOrderRefundTransfer($transfer, true); + $transfers[] = $transfer_tax; } else { // Create new transfer $transfer = $this->stripeTransferFactory->createFromOrderRefund($orderRefund); - $transfer_tax = $this->stripeTransferFactory->createFromOrderRefundForTax($orderRefund); + $transfer_tax = $this->stripeTransferFactory->createFromOrderRefundForTax($orderRefund); $this->stripeTransferRepository->persist($transfer); $this->stripeTransferRepository->persist($transfer_tax); - $transfers[]=$transfer_tax; + $transfers[] = $transfer_tax; } @@ -141,7 +141,7 @@ public function updateTransfers(array $transfers): array if(strpos($refundId, $_ENV['TAX_ORDER_POSTFIX']) !== false){ - $updated[$refundId] = $this->stripeTransferFactory->updateOrderRefundTransfer($transfer,true); + $updated[$refundId] = $this->stripeTransferFactory->updateOrderRefundTransfer($transfer, true); } else $updated[$refundId] = $this->stripeTransferFactory->updateOrderRefundTransfer($transfer); From 38e73f7cf1fbd7ac42d9b3af0e06fa73bda7faa4 Mon Sep 17 00:00:00 2001 From: millin-stripe <87815854+millin-stripe@users.noreply.github.com> Date: Wed, 18 Jan 2023 10:08:24 -0500 Subject: [PATCH 05/40] Code fix --- src/Service/PaymentRefundService.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Service/PaymentRefundService.php b/src/Service/PaymentRefundService.php index 30d712e9..18040a02 100644 --- a/src/Service/PaymentRefundService.php +++ b/src/Service/PaymentRefundService.php @@ -113,17 +113,15 @@ public function getTransfersFromOrderRefunds(array $orderRefunds): array // Create new transfer $transfer = $this->stripeTransferFactory->createFromOrderRefund($orderRefund); $transfer_tax = $this->stripeTransferFactory->createFromOrderRefundForTax($orderRefund); - $this->stripeTransferRepository->persist($transfer); $this->stripeTransferRepository->persist($transfer_tax); - $transfers[] = $transfer_tax; - + $transfers[] = $transfer_tax; } $transfers[] = $transfer; } - + // Save $this->stripeTransferRepository->flush(); From 978b2c869c499b9e9c8e974124bad330b6ac7af5 Mon Sep 17 00:00:00 2001 From: millin-stripe <87815854+millin-stripe@users.noreply.github.com> Date: Wed, 18 Jan 2023 10:11:44 -0500 Subject: [PATCH 06/40] Code Fix --- src/Service/PaymentSplitService.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Service/PaymentSplitService.php b/src/Service/PaymentSplitService.php index 7075d85a..51f9b7e1 100644 --- a/src/Service/PaymentSplitService.php +++ b/src/Service/PaymentSplitService.php @@ -91,8 +91,8 @@ public function updateTransfersFromOrders(array $existingTransfers, array $order foreach ($existingTransfers as $orderId => $transfer) { $pendingDebit = $pendingDebits[$orderId] ?? null; if(strpos($orderId, $_ENV['TAX_ORDER_POSTFIX']) !== false){ - $tax_suffixed_orderId= $orderId; - $orderId = str_replace($_ENV['TAX_ORDER_POSTFIX'],"",$orderId); + $tax_suffixed_orderId = $orderId; + $orderId = str_replace($_ENV['TAX_ORDER_POSTFIX'], "", $orderId); $pendingDebit = $pendingDebits[$orderId] ?? null; $updated[$tax_suffixed_orderId] = $this->stripeTransferFactory->updateFromOrder( $transfer, From b163c19af1dd62e646b27cf87dd65ad2c8355821 Mon Sep 17 00:00:00 2001 From: millin-stripe <87815854+millin-stripe@users.noreply.github.com> Date: Wed, 18 Jan 2023 10:14:47 -0500 Subject: [PATCH 07/40] Update code format --- src/Service/MiraklClient.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Service/MiraklClient.php b/src/Service/MiraklClient.php index f0819ce6..52f500ea 100644 --- a/src/Service/MiraklClient.php +++ b/src/Service/MiraklClient.php @@ -172,7 +172,7 @@ public function listProductOrdersByDate(string $datetime) // OR11 by order_id public function listProductOrdersById(array $orderIds) { - $orderIds = array_map(array($this, 'removeTaxKeword'),$orderIds); + $orderIds = array_map(array($this, 'removeTaxKeword'), $orderIds); $res = []; foreach (array_chunk($orderIds, 100) as $chunk) { $res = array_merge($res, $this->paginateByOffset('/api/orders', ['order_ids' => implode(',', $chunk)], 'orders')); @@ -256,7 +256,7 @@ public function listServiceOrdersByDate(string $datetime) // SOR11 by order_id public function listServiceOrdersById(array $orderIds) { - $orderIds = array_map(array($this, 'removeTaxKeword'),$orderIds); + $orderIds = array_map(array($this, 'removeTaxKeword'), $orderIds); $res = $this->paginateByPage('/api/mms/orders', ['order_id' => $orderIds], 'data'); $res = $this->arraysToObjects($res, MiraklServiceOrder::class); return $this->objectsToMap($res, 'getId'); @@ -281,7 +281,7 @@ public function listServicePendingDebits() // SPA11 by order ID public function listServicePendingDebitsByOrderIds(array $orderIds) { - $orderIds = array_map(array($this, 'removeTaxKeword'),$orderIds); + $orderIds = array_map(array($this, 'removeTaxKeword'), $orderIds); $res = $this->paginateByPage('/api/mms/debits', ['order_id' => $orderIds], 'data'); $res = $this->arraysToObjects($res, MiraklServicePendingDebit::class); return $this->objectsToMap($res, 'getOrderId'); @@ -370,7 +370,6 @@ public function updateShopKycStatus(int $shopId, string $status) ]]]); } - public function getTransactionsForInvoce(string $invoiceId) { $params['accounting_document_number'] = $invoiceId; @@ -393,6 +392,6 @@ public static function getStringFromDatetime(\DateTimeInterface $date): string } private function removeTaxKeword($val) { - return str_replace($_ENV['TAX_ORDER_POSTFIX'],"",$val); + return str_replace($_ENV['TAX_ORDER_POSTFIX'], "", $val); } } From 358c1f5bfa4c33b2c1e93b2cb3f3422492b4529c Mon Sep 17 00:00:00 2001 From: millin-stripe <87815854+millin-stripe@users.noreply.github.com> Date: Wed, 18 Jan 2023 10:18:11 -0500 Subject: [PATCH 08/40] Code White Spaces Removed --- src/Entity/MiraklProductOrder.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Entity/MiraklProductOrder.php b/src/Entity/MiraklProductOrder.php index 882cf665..a78cf611 100644 --- a/src/Entity/MiraklProductOrder.php +++ b/src/Entity/MiraklProductOrder.php @@ -151,17 +151,17 @@ protected function getRefundLineTaxes(array $refundLine): float return $taxes; } - + public function getCurrency(): string { return $this->order['currency_iso_code']; } - + public function getOrderLines(): array { return $this->order['order_lines'] ?? []; } - + protected function getOrderLineTaxes(array $orderLine): float { $taxes = 0; @@ -169,10 +169,10 @@ protected function getOrderLineTaxes(array $orderLine): float foreach ($allTaxes as $tax) { $taxes += (float) $tax['amount']; } - + return $taxes; } - + protected function getOrderLineCanceledAmountWithTaxes(array $canceledOrderLines): float { $canceledAmount = 0; @@ -185,7 +185,7 @@ protected function getOrderLineCanceledAmountWithTaxes(array $canceledOrderLines return $canceledAmount; } - + public function getOrderTaxTotal(): float { $amount = 0; @@ -196,7 +196,7 @@ public function getOrderTaxTotal(): float } return $amount; } - + protected function getOrderLineOrderTaxes(array $orderLine): float { $taxes = 0; From 7836b151cf3f51e8f13102e81176b92a0ba9d3be Mon Sep 17 00:00:00 2001 From: millin-stripe <87815854+millin-stripe@users.noreply.github.com> Date: Wed, 18 Jan 2023 10:21:10 -0500 Subject: [PATCH 09/40] Removed WhiteSpace --- src/Entity/MiraklServiceOrder.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Entity/MiraklServiceOrder.php b/src/Entity/MiraklServiceOrder.php index 37456d38..f534930e 100644 --- a/src/Entity/MiraklServiceOrder.php +++ b/src/Entity/MiraklServiceOrder.php @@ -111,7 +111,7 @@ public function getRefundedOperatorCommission(StripeRefund $refund): float public function getRefundedTax(StripeRefund $refund): float { - + foreach ($this->order['refunds'] as $orderRefund) { if ($refund->getMiraklRefundId() === $orderRefund['id']) { if ($refund->getMiraklRefundId() === $orderRefund['id']) { @@ -134,12 +134,12 @@ protected function getRefundLineTaxes(array $refundLine): float return $taxes; } - + public function getCurrency(): string { return $this->order['currency_code']; } - + public function getOrderTaxTotal(): float { $taxes = 0; From 7513bf3deb61176e0e981b46a653f5426118efbc Mon Sep 17 00:00:00 2001 From: millin-stripe <87815854+millin-stripe@users.noreply.github.com> Date: Wed, 18 Jan 2023 10:25:11 -0500 Subject: [PATCH 10/40] Fixed Spaces --- src/Factory/StripePayoutFactory.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Factory/StripePayoutFactory.php b/src/Factory/StripePayoutFactory.php index e175f0dd..736a108a 100644 --- a/src/Factory/StripePayoutFactory.php +++ b/src/Factory/StripePayoutFactory.php @@ -22,7 +22,7 @@ class StripePayoutFactory implements LoggerAwareInterface /** * @var MiraklClient */ - + public function __construct( AccountMappingRepository $accountMappingRepository ) { @@ -33,7 +33,7 @@ public function __construct( * @param array $invoice * @return StripePayout */ - public function createFromInvoice(array $invoice,MiraklClient $mclient): StripePayout + public function createFromInvoice(array $invoice, MiraklClient $mclient): StripePayout { $payout = new StripePayout(); $payout->setMiraklInvoiceId($invoice['invoice_id']); @@ -41,7 +41,7 @@ public function createFromInvoice(array $invoice,MiraklClient $mclient): StripeP MiraklClient::getDatetimeFromString($invoice['date_created']) ); - return $this->updateFromInvoice($payout, $invoice,$mclient); + return $this->updateFromInvoice($payout, $invoice, $mclient); } /** @@ -49,7 +49,7 @@ public function createFromInvoice(array $invoice,MiraklClient $mclient): StripeP * @param array $invoice * @return StripePayout */ - public function updateFromInvoice(StripePayout $payout, array $invoice,MiraklClient $mclient): StripePayout + public function updateFromInvoice(StripePayout $payout, array $invoice, MiraklClient $mclient): StripePayout { // Payout already created if ($payout->getPayoutId()) { @@ -58,7 +58,7 @@ public function updateFromInvoice(StripePayout $payout, array $invoice,MiraklCli // Amount and currency try { - $payout->setAmount($this->getInvoiceAmount($invoice,$mclient)); + $payout->setAmount($this->getInvoiceAmount($invoice, $mclient)); $payout->setCurrency(strtolower($invoice['currency_iso_code'])); } catch (InvalidArgumentException $e) { return $this->abortPayout($payout, $e->getMessage()); @@ -122,11 +122,10 @@ private function getAccountMapping(int $shopId): AccountMapping * @param array $invoice * @return int */ - private function getInvoiceAmount(array $invoice,MiraklClient $mclient ): int + private function getInvoiceAmount(array $invoice, MiraklClient $mclient ): int { $amount = $invoice['summary']['amount_transferred'] ?? 0; $transactions = $mclient->getTransactionsForInvoce($invoice['invoice_id']); - $total_tax = $this->findTotalOrderTax($transactions); $amount = $amount - $total_tax; $amount = gmp_intval((string) ($amount * 100)); @@ -194,7 +193,6 @@ private function findTotalOrderTax($transactions) { $taxes += (float) $trx['amount']; } } - return $taxes; - + return $taxes; } } From c66d2a8655be346dc105728064efd1951f25699d Mon Sep 17 00:00:00 2001 From: Tejpal Singh Date: Wed, 18 Jan 2023 21:44:12 +0530 Subject: [PATCH 11/40] fixed getInvoiceAmount return type issue --- src/Factory/StripePayoutFactory.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Factory/StripePayoutFactory.php b/src/Factory/StripePayoutFactory.php index 736a108a..73242601 100644 --- a/src/Factory/StripePayoutFactory.php +++ b/src/Factory/StripePayoutFactory.php @@ -125,9 +125,9 @@ private function getAccountMapping(int $shopId): AccountMapping private function getInvoiceAmount(array $invoice, MiraklClient $mclient ): int { $amount = $invoice['summary']['amount_transferred'] ?? 0; - $transactions = $mclient->getTransactionsForInvoce($invoice['invoice_id']); - $total_tax = $this->findTotalOrderTax($transactions); - $amount = $amount - $total_tax; + $transactions = $mclient->getTransactionsForInvoce($invoice['invoice_id']); + $total_tax = $this->findTotalOrderTax($transactions); + $amount = $amount - $total_tax; $amount = gmp_intval((string) ($amount * 100)); if ($amount <= 0) { throw new InvalidArgumentException(sprintf( @@ -186,7 +186,8 @@ private function markPayoutAsCreated(StripePayout $payout): StripePayout return $payout->setStatus(StripePayout::PAYOUT_CREATED); } - private function findTotalOrderTax($transactions) { + private function findTotalOrderTax($transactions): int + { $taxes=0; foreach ($transactions as $trx) { if($trx['type']=='ORDER_AMOUNT_TAX'){ From 355b8910eef35f416a39aea24a2978fc45fb7fc3 Mon Sep 17 00:00:00 2001 From: millin-stripe <87815854+millin-stripe@users.noreply.github.com> Date: Thu, 19 Jan 2023 10:56:18 -0500 Subject: [PATCH 12/40] Updated for code compliance --- src/Factory/StripeTransferFactory.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Factory/StripeTransferFactory.php b/src/Factory/StripeTransferFactory.php index a5e48093..70163fd6 100644 --- a/src/Factory/StripeTransferFactory.php +++ b/src/Factory/StripeTransferFactory.php @@ -105,7 +105,7 @@ public function createFromOrderForTax(MiraklOrder $order, MiraklPendingDebit $pe $transfer->setMiraklId($order->getId().$_ENV['TAX_ORDER_POSTFIX']); $transfer->setMiraklCreatedDate($order->getCreationDateAsDateTime()); - return $this->updateFromOrder($transfer, $order, $pendingDebit,true); + return $this->updateFromOrder($transfer, $order, $pendingDebit, true); } /** @@ -256,7 +256,7 @@ public function createFromOrderRefundForTax(MiraklPendingRefund $orderRefund): S $transfer->setType(StripeTransfer::TRANSFER_REFUND); $transfer->setMiraklId($orderRefund->getId().$_ENV['TAX_ORDER_POSTFIX']); - return $this->updateOrderRefundTransfer($transfer,true); + return $this->updateOrderRefundTransfer($transfer, true); } /** @@ -273,7 +273,7 @@ public function updateOrderRefundTransfer(StripeTransfer $transfer, $isForTax = // Check corresponding StripeRefund $refund = null; try { - $refund = $this->findRefundFromRefundId(str_replace($_ENV['TAX_ORDER_POSTFIX'],"",$transfer->getMiraklId())); + $refund = $this->findRefundFromRefundId(str_replace($_ENV['TAX_ORDER_POSTFIX'], "", $transfer->getMiraklId())); // Fetch transfer to be reversed $orderIds = [$refund->getMiraklOrderId()]; @@ -305,20 +305,16 @@ public function updateOrderRefundTransfer(StripeTransfer $transfer, $isForTax = // Amount and currency $transferAmount = $refund->getAmount(); - $commission = $order->getRefundedOperatorCommission($refund); $commission = gmp_intval((string) ($commission * 100)); - $refundedTax = $order->getRefundedTax($refund); $refundedTax = gmp_intval((string) ($refundedTax * 100)); - $transferAmount = $transferAmount - $commission - $refundedTax; - if($isForTax) $transferAmount = $refundedTax; - $transfer->setAmount($transferAmount); + $transfer->setAmount($transferAmount); $transfer->setCurrency(strtolower($order->getCurrency())); } catch (InvalidArgumentException $e) { switch ($e->getCode()) { From 233c514b3bb590a7f645318dae9bde7a3903508a Mon Sep 17 00:00:00 2001 From: millin-stripe <87815854+millin-stripe@users.noreply.github.com> Date: Thu, 19 Jan 2023 10:57:49 -0500 Subject: [PATCH 13/40] Update code compliance --- src/Command/SellerSettlementCommand.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Command/SellerSettlementCommand.php b/src/Command/SellerSettlementCommand.php index 0a7375b9..ba1bbf8b 100644 --- a/src/Command/SellerSettlementCommand.php +++ b/src/Command/SellerSettlementCommand.php @@ -91,7 +91,7 @@ private function processProvidedShopId(int $shopId) ); $this->dispatchPayouts( - $this->sellerSettlementService->getPayoutsFromInvoices($invoices,$this->miraklClient) + $this->sellerSettlementService->getPayoutsFromInvoices($invoices, $this->miraklClient) ); } @@ -151,7 +151,7 @@ private function processNewInvoices() ); $this->dispatchPayouts( - $this->sellerSettlementService->getPayoutsFromInvoices($invoices,$this->miraklClient) + $this->sellerSettlementService->getPayoutsFromInvoices($invoices, $this->miraklClient) ); $checkpoint = $this->updateCheckpoint($invoices, $checkpoint); From d629064462633ca6088a05256e3ba057be6503c6 Mon Sep 17 00:00:00 2001 From: millin-stripe <87815854+millin-stripe@users.noreply.github.com> Date: Thu, 19 Jan 2023 11:03:25 -0500 Subject: [PATCH 14/40] code compliance --- src/Command/SellerSettlementCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Command/SellerSettlementCommand.php b/src/Command/SellerSettlementCommand.php index ba1bbf8b..4fabd739 100644 --- a/src/Command/SellerSettlementCommand.php +++ b/src/Command/SellerSettlementCommand.php @@ -114,7 +114,7 @@ private function processBacklog() $this->dispatchTransfers($transfersByInvoiceId); $payouts = $this->sellerSettlementService - ->updatePayoutsFromInvoices($retriablePayouts, $invoices,$this->miraklClient); + ->updatePayoutsFromInvoices($retriablePayouts, $invoices, $this->miraklClient); $this->dispatchPayouts($payouts); } From e468e548d8d708ac396f5828dba42f83e2403fff Mon Sep 17 00:00:00 2001 From: millin-stripe <87815854+millin-stripe@users.noreply.github.com> Date: Thu, 19 Jan 2023 11:08:07 -0500 Subject: [PATCH 15/40] remove white space --- src/Entity/MiraklProductOrder.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Entity/MiraklProductOrder.php b/src/Entity/MiraklProductOrder.php index a78cf611..bde20b9f 100644 --- a/src/Entity/MiraklProductOrder.php +++ b/src/Entity/MiraklProductOrder.php @@ -123,7 +123,6 @@ public function getRefundedOperatorCommission(StripeRefund $refund): float return 0; } - public function getRefundedTax(StripeRefund $refund): float { foreach ($this->getOrderLines() as $line) { From 76e376910f8fe31d236a82891bed63ece7d9999e Mon Sep 17 00:00:00 2001 From: millin-stripe <87815854+millin-stripe@users.noreply.github.com> Date: Thu, 19 Jan 2023 11:39:02 -0500 Subject: [PATCH 16/40] Code Updates for braces --- src/Service/PaymentSplitService.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Service/PaymentSplitService.php b/src/Service/PaymentSplitService.php index 51f9b7e1..e7ce2934 100644 --- a/src/Service/PaymentSplitService.php +++ b/src/Service/PaymentSplitService.php @@ -90,7 +90,7 @@ public function updateTransfersFromOrders(array $existingTransfers, array $order $updated = []; foreach ($existingTransfers as $orderId => $transfer) { $pendingDebit = $pendingDebits[$orderId] ?? null; - if(strpos($orderId, $_ENV['TAX_ORDER_POSTFIX']) !== false){ + if(strpos($orderId, $_ENV['TAX_ORDER_POSTFIX']) !== false) { $tax_suffixed_orderId = $orderId; $orderId = str_replace($_ENV['TAX_ORDER_POSTFIX'], "", $orderId); $pendingDebit = $pendingDebits[$orderId] ?? null; @@ -100,7 +100,8 @@ public function updateTransfersFromOrders(array $existingTransfers, array $order $pendingDebit, true ); - }else{ + } + else { $updated[$orderId] = $this->stripeTransferFactory->updateFromOrder( $transfer, $orders[$orderId], From 36460029851827ed10c9289faebf36f33bbbe9ec Mon Sep 17 00:00:00 2001 From: millin-stripe <87815854+millin-stripe@users.noreply.github.com> Date: Thu, 19 Jan 2023 11:44:25 -0500 Subject: [PATCH 17/40] Fixed brace on 193 --- src/Factory/StripePayoutFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Factory/StripePayoutFactory.php b/src/Factory/StripePayoutFactory.php index 73242601..fa66e179 100644 --- a/src/Factory/StripePayoutFactory.php +++ b/src/Factory/StripePayoutFactory.php @@ -190,7 +190,7 @@ private function findTotalOrderTax($transactions): int { $taxes=0; foreach ($transactions as $trx) { - if($trx['type']=='ORDER_AMOUNT_TAX'){ + if($trx['type']=='ORDER_AMOUNT_TAX') { $taxes += (float) $trx['amount']; } } From b4a2af43c77a5d699fc8aadb6b35e387e0d65f12 Mon Sep 17 00:00:00 2001 From: millin-stripe <87815854+millin-stripe@users.noreply.github.com> Date: Thu, 19 Jan 2023 12:03:29 -0500 Subject: [PATCH 18/40] Ran PHP fix --- src/Factory/StripePayoutFactory.php | 238 +++++++++------------------- 1 file changed, 79 insertions(+), 159 deletions(-) diff --git a/src/Factory/StripePayoutFactory.php b/src/Factory/StripePayoutFactory.php index fa66e179..c3ee9ba0 100644 --- a/src/Factory/StripePayoutFactory.php +++ b/src/Factory/StripePayoutFactory.php @@ -1,199 +1,119 @@ accountMappingRepository = $accountMappingRepository; + $this->stripeTransferFactory = $stripeTransferFactory; + $this->stripeTransferRepository = $stripeTransferRepository; } /** - * @param array $invoice - * @return StripePayout + * @return array App\Entity\StripeTransfer[] */ - public function createFromInvoice(array $invoice, MiraklClient $mclient): StripePayout + public function getRetriableProductTransfers(): array { - $payout = new StripePayout(); - $payout->setMiraklInvoiceId($invoice['invoice_id']); - $payout->setMiraklCreatedDate( - MiraklClient::getDatetimeFromString($invoice['date_created']) - ); - - return $this->updateFromInvoice($payout, $invoice, $mclient); + return $this->stripeTransferRepository->findRetriableProductOrderTransfers(); } /** - * @param StripePayout $payout - * @param array $invoice - * @return StripePayout + * @return array App\Entity\StripeTransfer[] */ - public function updateFromInvoice(StripePayout $payout, array $invoice, MiraklClient $mclient): StripePayout + public function getRetriableServiceTransfers(): array { - // Payout already created - if ($payout->getPayoutId()) { - return $this->markPayoutAsCreated($payout); - } - - // Amount and currency - try { - $payout->setAmount($this->getInvoiceAmount($invoice, $mclient)); - $payout->setCurrency(strtolower($invoice['currency_iso_code'])); - } catch (InvalidArgumentException $e) { - return $this->abortPayout($payout, $e->getMessage()); - } - - // Save Stripe account corresponding with this shop - try { - $payout->setAccountMapping( - $this->getAccountMapping($invoice['shop_id'] ?? 0) - ); - } catch (InvalidArgumentException $e) { - switch ($e->getCode()) { - // Problem is final, let's abort - case 10: - return $this->abortPayout($payout, $e->getMessage()); - // Problem is just temporary, let's put on hold - case 20: - return $this->putPayoutOnHold($payout, $e->getMessage()); - } - } - - // All good - return $payout->setStatus(StripePayout::PAYOUT_PENDING); + return $this->stripeTransferRepository->findRetriableServiceOrderTransfers(); } /** - * @param int $shopId - * @return AccountMapping + * @param array $orders + * @return array App\Entity\StripeTransfer[] */ - private function getAccountMapping(int $shopId): AccountMapping + public function getTransfersFromOrders(array $orders, array $pendingDebits): array { - if (!$shopId) { - throw new InvalidArgumentException( - StripePayout::PAYOUT_STATUS_REASON_NO_SHOP_ID, - 10 - ); - } - - $mapping = $this->accountMappingRepository->findOneBy([ - 'miraklShopId' => $shopId - ]); + // Retrieve existing StripeTransfers with provided order IDs + $existingTransfers = $this->stripeTransferRepository + ->findTransfersByOrderIds(array_keys($orders)); + + $transfers = []; + foreach ($orders as $orderId => $order) { + $pendingDebit = $pendingDebits[$orderId] ?? null; + if (isset($existingTransfers[$orderId])) { + $transfer = $existingTransfers[$orderId]; + if (!$transfer->isRetriable()) { + continue; + } + + // Use existing transfer + $transfer = $this->stripeTransferFactory->updateFromOrder($transfer, $order, $pendingDebit); + } else { + // Create new transfer + $transfer = $this->stripeTransferFactory->createFromOrder($order, $pendingDebit); + $this->stripeTransferRepository->persist($transfer); + $tax_transfer = $this->stripeTransferFactory->createFromOrderForTax($order, $pendingDebit); + $this->stripeTransferRepository->persist($tax_transfer); + } - if (!$mapping) { - throw new InvalidArgumentException(sprintf( - StripePayout::PAYOUT_STATUS_REASON_SHOP_NOT_READY, - $shopId - ), 20); + $transfers[] = $transfer; + if (isset($tax_transfer)) { + $transfers[] = $tax_transfer; + } } - if (!$mapping->getPayoutEnabled()) { - throw new InvalidArgumentException(sprintf( - StripePayout::PAYOUT_STATUS_REASON_SHOP_PAYOUT_DISABLED, - $shopId - ), 20); - } + // Save + $this->stripeTransferRepository->flush(); - return $mapping; + return $transfers; } /** - * @param array $invoice - * @return int + * @param array $existingTransfers + * @param array $orders + * @return array App\Entity\StripeTransfer[] */ - private function getInvoiceAmount(array $invoice, MiraklClient $mclient ): int + public function updateTransfersFromOrders(array $existingTransfers, array $orders, array $pendingDebits) { - $amount = $invoice['summary']['amount_transferred'] ?? 0; - $transactions = $mclient->getTransactionsForInvoce($invoice['invoice_id']); - $total_tax = $this->findTotalOrderTax($transactions); - $amount = $amount - $total_tax; - $amount = gmp_intval((string) ($amount * 100)); - if ($amount <= 0) { - throw new InvalidArgumentException(sprintf( - StripePayout::PAYOUT_STATUS_REASON_INVALID_AMOUNT, - $amount - )); + $updated = []; + foreach ($existingTransfers as $orderId => $transfer) { + $pendingDebit = $pendingDebits[$orderId] ?? null; + if (strpos($orderId, $_ENV['TAX_ORDER_POSTFIX']) !== false) { + $tax_suffixed_orderId = $orderId; + $orderId = str_replace($_ENV['TAX_ORDER_POSTFIX'], "", $orderId); + $pendingDebit = $pendingDebits[$orderId] ?? null; + $updated[$tax_suffixed_orderId] = $this->stripeTransferFactory->updateFromOrder( + $transfer, + $orders[$orderId], + $pendingDebit, + true + ); + } else { + $updated[$orderId] = $this->stripeTransferFactory->updateFromOrder( + $transfer, + $orders[$orderId], + $pendingDebit + ); + } } - return $amount; - } - - /** - * @param StripePayout $payout - * @param string $reason - * @return StripePayout - */ - private function putPayoutOnHold(StripePayout $payout, string $reason): StripePayout - { - $this->logger->info( - 'Payout on hold: ' . $reason, - ['invoice_id' => $payout->getMiraklInvoiceId()] - ); - - $payout->setStatusReason($reason); - return $payout->setStatus(StripePayout::PAYOUT_ON_HOLD); - } + // Save + $this->stripeTransferRepository->flush(); - /** - * @param StripePayout $payout - * @param string $reason - * @return StripePayout - */ - private function abortPayout(StripePayout $payout, string $reason): StripePayout - { - $this->logger->info( - 'Payout aborted: ' . $reason, - ['invoice_id' => $payout->getMiraklInvoiceId()] - ); - - $payout->setStatusReason($reason); - return $payout->setStatus(StripePayout::PAYOUT_ABORTED); - } - - /** - * @param StripePayout $payout - * @return StripePayout - */ - private function markPayoutAsCreated(StripePayout $payout): StripePayout - { - $this->logger->info( - 'Payout created', - ['invoice_id' => $payout->getMiraklInvoiceId()] - ); - - $payout->setStatusReason(null); - return $payout->setStatus(StripePayout::PAYOUT_CREATED); - } - - private function findTotalOrderTax($transactions): int - { - $taxes=0; - foreach ($transactions as $trx) { - if($trx['type']=='ORDER_AMOUNT_TAX') { - $taxes += (float) $trx['amount']; - } - } - return $taxes; + return $updated; } } From 56f0a2f6a921c1525c23658c35f684b3bf948cff Mon Sep 17 00:00:00 2001 From: millin-stripe <87815854+millin-stripe@users.noreply.github.com> Date: Thu, 19 Jan 2023 12:07:56 -0500 Subject: [PATCH 19/40] Code Fixer --- src/Service/PaymentSplitService.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Service/PaymentSplitService.php b/src/Service/PaymentSplitService.php index e7ce2934..c3ee9ba0 100644 --- a/src/Service/PaymentSplitService.php +++ b/src/Service/PaymentSplitService.php @@ -71,7 +71,9 @@ public function getTransfersFromOrders(array $orders, array $pendingDebits): arr } $transfers[] = $transfer; - if(isset($tax_transfer)) $transfers[] = $tax_transfer; + if (isset($tax_transfer)) { + $transfers[] = $tax_transfer; + } } // Save @@ -90,7 +92,7 @@ public function updateTransfersFromOrders(array $existingTransfers, array $order $updated = []; foreach ($existingTransfers as $orderId => $transfer) { $pendingDebit = $pendingDebits[$orderId] ?? null; - if(strpos($orderId, $_ENV['TAX_ORDER_POSTFIX']) !== false) { + if (strpos($orderId, $_ENV['TAX_ORDER_POSTFIX']) !== false) { $tax_suffixed_orderId = $orderId; $orderId = str_replace($_ENV['TAX_ORDER_POSTFIX'], "", $orderId); $pendingDebit = $pendingDebits[$orderId] ?? null; @@ -100,8 +102,7 @@ public function updateTransfersFromOrders(array $existingTransfers, array $order $pendingDebit, true ); - } - else { + } else { $updated[$orderId] = $this->stripeTransferFactory->updateFromOrder( $transfer, $orders[$orderId], From 375c8d6e818cb859603a4eaf4bcfee1f9b7b8abc Mon Sep 17 00:00:00 2001 From: millin-stripe <87815854+millin-stripe@users.noreply.github.com> Date: Thu, 19 Jan 2023 12:09:52 -0500 Subject: [PATCH 20/40] Code Fixer --- src/Service/PaymentRefundService.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/Service/PaymentRefundService.php b/src/Service/PaymentRefundService.php index 18040a02..5ab09050 100644 --- a/src/Service/PaymentRefundService.php +++ b/src/Service/PaymentRefundService.php @@ -108,20 +108,18 @@ public function getTransfersFromOrderRefunds(array $orderRefunds): array $transfer = $this->stripeTransferFactory->updateOrderRefundTransfer($transfer); $transfer_tax = $this->stripeTransferFactory->updateOrderRefundTransfer($transfer, true); $transfers[] = $transfer_tax; - } else { // Create new transfer $transfer = $this->stripeTransferFactory->createFromOrderRefund($orderRefund); $transfer_tax = $this->stripeTransferFactory->createFromOrderRefundForTax($orderRefund); $this->stripeTransferRepository->persist($transfer); $this->stripeTransferRepository->persist($transfer_tax); - $transfers[] = $transfer_tax; + $transfers[] = $transfer_tax; } - + $transfers[] = $transfer; - } - + // Save $this->stripeTransferRepository->flush(); @@ -136,13 +134,11 @@ public function updateTransfers(array $transfers): array { $updated = []; foreach ($transfers as $refundId => $transfer) { - - if(strpos($refundId, $_ENV['TAX_ORDER_POSTFIX']) !== false){ - + if (strpos($refundId, $_ENV['TAX_ORDER_POSTFIX']) !== false) { $updated[$refundId] = $this->stripeTransferFactory->updateOrderRefundTransfer($transfer, true); - } - else + } else { $updated[$refundId] = $this->stripeTransferFactory->updateOrderRefundTransfer($transfer); + } } // Save From a9ff467cd3075c20579da158e9153a238864f18a Mon Sep 17 00:00:00 2001 From: millin-stripe <87815854+millin-stripe@users.noreply.github.com> Date: Thu, 19 Jan 2023 12:11:01 -0500 Subject: [PATCH 21/40] Code Fixer --- src/Service/MiraklClient.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Service/MiraklClient.php b/src/Service/MiraklClient.php index 52f500ea..c87d48d0 100644 --- a/src/Service/MiraklClient.php +++ b/src/Service/MiraklClient.php @@ -369,7 +369,7 @@ public function updateShopKycStatus(int $shopId, string $status) 'kyc' => ['status' => $status] ]]]); } - + public function getTransactionsForInvoce(string $invoiceId) { $params['accounting_document_number'] = $invoiceId; @@ -390,8 +390,9 @@ public static function getStringFromDatetime(\DateTimeInterface $date): string { return $date->format(self::DATE_FORMAT); } - - private function removeTaxKeword($val) { + + private function removeTaxKeword($val) + { return str_replace($_ENV['TAX_ORDER_POSTFIX'], "", $val); } } From 8469f7cc791c6ed66385761c0e6a4c2773981b4c Mon Sep 17 00:00:00 2001 From: millin-stripe <87815854+millin-stripe@users.noreply.github.com> Date: Thu, 19 Jan 2023 12:12:26 -0500 Subject: [PATCH 22/40] Code Fixer --- src/Factory/StripeTransferFactory.php | 36 +++++++++++++-------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Factory/StripeTransferFactory.php b/src/Factory/StripeTransferFactory.php index 70163fd6..feee9187 100644 --- a/src/Factory/StripeTransferFactory.php +++ b/src/Factory/StripeTransferFactory.php @@ -91,7 +91,7 @@ public function createFromOrder(MiraklOrder $order, MiraklPendingDebit $pendingD return $this->updateFromOrder($transfer, $order, $pendingDebit); } - + public function createFromOrderForTax(MiraklOrder $order, MiraklPendingDebit $pendingDebit = null): StripeTransfer { if (is_a($order, MiraklServiceOrder::class)) { @@ -99,12 +99,12 @@ public function createFromOrderForTax(MiraklOrder $order, MiraklPendingDebit $pe } else { $type = StripeTransfer::TRANSFER_PRODUCT_ORDER; } - + $transfer = new StripeTransfer(); $transfer->setType($type); $transfer->setMiraklId($order->getId().$_ENV['TAX_ORDER_POSTFIX']); $transfer->setMiraklCreatedDate($order->getCreationDateAsDateTime()); - + return $this->updateFromOrder($transfer, $order, $pendingDebit, true); } @@ -122,11 +122,9 @@ public function updateFromOrder(StripeTransfer $transfer, MiraklOrder $order, Mi // Shop must have a Stripe account try { - if(!$isForTax){ + if (!$isForTax) { $accountMapping = $this->getAccountMapping($order->getShopId()); - } - else - { + } else { $accountMapping = $this->accountMappingRepository->findOneByStripeAccountId($_ENV['STRIPE_TAX_ACCOUNT']); } $transfer->setAccountMapping($accountMapping); @@ -204,7 +202,7 @@ public function updateFromOrder(StripeTransfer $transfer, MiraklOrder $order, Mi ); } catch (InvalidArgumentException $e) { switch ($e->getCode()) { - // Problem is final, let's abort + // Problem is final, let's abort case 10: return $this->abortTransfer($transfer, $e->getMessage()); // Problem is just temporary, let's put on hold @@ -220,7 +218,7 @@ public function updateFromOrder(StripeTransfer $transfer, MiraklOrder $order, Mi $transferAmount = $amount - $commission; $orderTaxTotal = $order->getOrderTaxTotal(); $transferAmount = $transferAmount - $orderTaxTotal; - if($isForTax){ + if ($isForTax) { $transferAmount = $orderTaxTotal; } if ($transferAmount <= 0) { @@ -249,13 +247,13 @@ public function createFromOrderRefund(MiraklPendingRefund $orderRefund): StripeT return $this->updateOrderRefundTransfer($transfer); } - + public function createFromOrderRefundForTax(MiraklPendingRefund $orderRefund): StripeTransfer { $transfer = new StripeTransfer(); $transfer->setType(StripeTransfer::TRANSFER_REFUND); $transfer->setMiraklId($orderRefund->getId().$_ENV['TAX_ORDER_POSTFIX']); - + return $this->updateOrderRefundTransfer($transfer, true); } @@ -277,9 +275,10 @@ public function updateOrderRefundTransfer(StripeTransfer $transfer, $isForTax = // Fetch transfer to be reversed $orderIds = [$refund->getMiraklOrderId()]; - if($isForTax) + if ($isForTax) { $orderIds = [$refund->getMiraklOrderId().$_ENV['TAX_ORDER_POSTFIX']]; - + } + $orderTransfer = current($this->stripeTransferRepository->findTransfersByOrderIds($orderIds)); // Check order transfer status @@ -310,15 +309,16 @@ public function updateOrderRefundTransfer(StripeTransfer $transfer, $isForTax = $refundedTax = $order->getRefundedTax($refund); $refundedTax = gmp_intval((string) ($refundedTax * 100)); $transferAmount = $transferAmount - $commission - $refundedTax; - - if($isForTax) + + if ($isForTax) { $transferAmount = $refundedTax; - + } + $transfer->setAmount($transferAmount); $transfer->setCurrency(strtolower($order->getCurrency())); } catch (InvalidArgumentException $e) { switch ($e->getCode()) { - // Problem is final, let's abort + // Problem is final, let's abort case 10: return $this->abortTransfer($transfer, $e->getMessage()); // Problem is just temporary, let's put on hold @@ -372,7 +372,7 @@ public function updateFromInvoice(StripeTransfer $transfer, array $invoice, stri $transfer->setAccountMapping($this->getAccountMapping($invoice['shop_id'] ?? 0)); } catch (InvalidArgumentException $e) { switch ($e->getCode()) { - // Problem is final, let's abort + // Problem is final, let's abort case 10: return $this->abortTransfer($transfer, $e->getMessage()); // Problem is just temporary, let's put on hold From c8f94d0cf3077216d494bf275b4dbb8401537673 Mon Sep 17 00:00:00 2001 From: millin-stripe <87815854+millin-stripe@users.noreply.github.com> Date: Thu, 19 Jan 2023 12:13:40 -0500 Subject: [PATCH 23/40] Code Fixer --- src/Entity/MiraklServiceOrder.php | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/Entity/MiraklServiceOrder.php b/src/Entity/MiraklServiceOrder.php index f534930e..c52de15b 100644 --- a/src/Entity/MiraklServiceOrder.php +++ b/src/Entity/MiraklServiceOrder.php @@ -108,21 +108,20 @@ public function getRefundedOperatorCommission(StripeRefund $refund): float return 0; } - + public function getRefundedTax(StripeRefund $refund): float { - - foreach ($this->order['refunds'] as $orderRefund) { - if ($refund->getMiraklRefundId() === $orderRefund['id']) { - if ($refund->getMiraklRefundId() === $orderRefund['id']) { - return $this->getRefundLineTaxes($orderRefund);//$orderRefund['commission_total_amount']; - } + foreach ($this->order['refunds'] as $orderRefund) { + if ($refund->getMiraklRefundId() === $orderRefund['id']) { + if ($refund->getMiraklRefundId() === $orderRefund['id']) { + return $this->getRefundLineTaxes($orderRefund);//$orderRefund['commission_total_amount']; + } } } - + return 0; } - + protected function getRefundLineTaxes(array $refundLine): float { $taxes = 0; @@ -130,20 +129,20 @@ protected function getRefundLineTaxes(array $refundLine): float foreach ($allTaxes as $tax) { $taxes += (float) $tax['amount']; } - - + + return $taxes; } - + public function getCurrency(): string { return $this->order['currency_code']; } - + public function getOrderTaxTotal(): float { $taxes = 0; - + if (!$this->isTaxIncluded()) { foreach (($this->order['price']['taxes'] ?? []) as $tax) { $taxes += (float) $tax['amount']; @@ -151,7 +150,7 @@ public function getOrderTaxTotal(): float } return $taxes; } - + protected function getOrderLineOrderTaxes(array $orderLine): float { $taxes = 0; From 0caff3d5c9d9cfd483bd2bbd95a3433aecf3b552 Mon Sep 17 00:00:00 2001 From: millin-stripe <87815854+millin-stripe@users.noreply.github.com> Date: Thu, 19 Jan 2023 12:14:27 -0500 Subject: [PATCH 24/40] Code Fixer --- src/Entity/MiraklProductOrder.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Entity/MiraklProductOrder.php b/src/Entity/MiraklProductOrder.php index bde20b9f..8cb2f19e 100644 --- a/src/Entity/MiraklProductOrder.php +++ b/src/Entity/MiraklProductOrder.php @@ -122,7 +122,7 @@ public function getRefundedOperatorCommission(StripeRefund $refund): float return 0; } - + public function getRefundedTax(StripeRefund $refund): float { foreach ($this->getOrderLines() as $line) { @@ -135,10 +135,10 @@ public function getRefundedTax(StripeRefund $refund): float } } } - + return 0; } - + protected function getRefundLineTaxes(array $refundLine): float { $taxes = 0; @@ -146,21 +146,21 @@ protected function getRefundLineTaxes(array $refundLine): float foreach ($allTaxes as $tax) { $taxes += (float) $tax['amount']; } - + return $taxes; } - - + + public function getCurrency(): string { return $this->order['currency_iso_code']; } - + public function getOrderLines(): array { return $this->order['order_lines'] ?? []; } - + protected function getOrderLineTaxes(array $orderLine): float { $taxes = 0; @@ -168,10 +168,10 @@ protected function getOrderLineTaxes(array $orderLine): float foreach ($allTaxes as $tax) { $taxes += (float) $tax['amount']; } - + return $taxes; } - + protected function getOrderLineCanceledAmountWithTaxes(array $canceledOrderLines): float { $canceledAmount = 0; @@ -184,7 +184,7 @@ protected function getOrderLineCanceledAmountWithTaxes(array $canceledOrderLines return $canceledAmount; } - + public function getOrderTaxTotal(): float { $amount = 0; @@ -195,7 +195,7 @@ public function getOrderTaxTotal(): float } return $amount; } - + protected function getOrderLineOrderTaxes(array $orderLine): float { $taxes = 0; From 22660fc4baed9d1c30053d8bacc210dc5fd86a88 Mon Sep 17 00:00:00 2001 From: Tejpal Singh Date: Tue, 24 Jan 2023 11:45:00 +0530 Subject: [PATCH 25/40] revert back : @millin-stripe Ran PHP fix --- src/Factory/StripePayoutFactory.php | 245 +++++++++++++++++++--------- 1 file changed, 167 insertions(+), 78 deletions(-) diff --git a/src/Factory/StripePayoutFactory.php b/src/Factory/StripePayoutFactory.php index c3ee9ba0..ef3fe0e4 100644 --- a/src/Factory/StripePayoutFactory.php +++ b/src/Factory/StripePayoutFactory.php @@ -1,119 +1,208 @@ stripeTransferFactory = $stripeTransferFactory; - $this->stripeTransferRepository = $stripeTransferRepository; + $this->accountMappingRepository = $accountMappingRepository; } /** - * @return array App\Entity\StripeTransfer[] + * @param array $invoice + * @return StripePayout */ - public function getRetriableProductTransfers(): array + public function createFromInvoice(array $invoice,MiraklClient $mclient): StripePayout { - return $this->stripeTransferRepository->findRetriableProductOrderTransfers(); + $payout = new StripePayout(); + $payout->setMiraklInvoiceId($invoice['invoice_id']); + $payout->setMiraklCreatedDate( + MiraklClient::getDatetimeFromString($invoice['date_created']) + ); + + return $this->updateFromInvoice($payout, $invoice,$mclient); } /** - * @return array App\Entity\StripeTransfer[] + * @param StripePayout $payout + * @param array $invoice + * @return StripePayout */ - public function getRetriableServiceTransfers(): array + public function updateFromInvoice(StripePayout $payout, array $invoice,MiraklClient $mclient): StripePayout { - return $this->stripeTransferRepository->findRetriableServiceOrderTransfers(); + // Payout already created + if ($payout->getPayoutId()) { + return $this->markPayoutAsCreated($payout); + } + + // Amount and currency + try { + $payout->setAmount($this->getInvoiceAmount($invoice,$mclient)); + $payout->setCurrency(strtolower($invoice['currency_iso_code'])); + } catch (InvalidArgumentException $e) { + return $this->abortPayout($payout, $e->getMessage()); + } + + // Save Stripe account corresponding with this shop + try { + $payout->setAccountMapping( + $this->getAccountMapping($invoice['shop_id'] ?? 0) + ); + } catch (InvalidArgumentException $e) { + switch ($e->getCode()) { + // Problem is final, let's abort + case 10: + return $this->abortPayout($payout, $e->getMessage()); + // Problem is just temporary, let's put on hold + case 20: + return $this->putPayoutOnHold($payout, $e->getMessage()); + } + } + + // All good + return $payout->setStatus(StripePayout::PAYOUT_PENDING); } /** - * @param array $orders - * @return array App\Entity\StripeTransfer[] + * @param int $shopId + * @return AccountMapping */ - public function getTransfersFromOrders(array $orders, array $pendingDebits): array + private function getAccountMapping(int $shopId): AccountMapping { - // Retrieve existing StripeTransfers with provided order IDs - $existingTransfers = $this->stripeTransferRepository - ->findTransfersByOrderIds(array_keys($orders)); - - $transfers = []; - foreach ($orders as $orderId => $order) { - $pendingDebit = $pendingDebits[$orderId] ?? null; - if (isset($existingTransfers[$orderId])) { - $transfer = $existingTransfers[$orderId]; - if (!$transfer->isRetriable()) { - continue; - } - - // Use existing transfer - $transfer = $this->stripeTransferFactory->updateFromOrder($transfer, $order, $pendingDebit); - } else { - // Create new transfer - $transfer = $this->stripeTransferFactory->createFromOrder($order, $pendingDebit); - $this->stripeTransferRepository->persist($transfer); - $tax_transfer = $this->stripeTransferFactory->createFromOrderForTax($order, $pendingDebit); - $this->stripeTransferRepository->persist($tax_transfer); - } + if (!$shopId) { + throw new InvalidArgumentException( + StripePayout::PAYOUT_STATUS_REASON_NO_SHOP_ID, + 10 + ); + } - $transfers[] = $transfer; - if (isset($tax_transfer)) { - $transfers[] = $tax_transfer; - } + $mapping = $this->accountMappingRepository->findOneBy([ + 'miraklShopId' => $shopId + ]); + + if (!$mapping) { + throw new InvalidArgumentException(sprintf( + StripePayout::PAYOUT_STATUS_REASON_SHOP_NOT_READY, + $shopId + ), 20); } - // Save - $this->stripeTransferRepository->flush(); + if (!$mapping->getPayoutEnabled()) { + throw new InvalidArgumentException(sprintf( + StripePayout::PAYOUT_STATUS_REASON_SHOP_PAYOUT_DISABLED, + $shopId + ), 20); + } - return $transfers; + return $mapping; } /** - * @param array $existingTransfers - * @param array $orders - * @return array App\Entity\StripeTransfer[] + * @param array $invoice + * @return int */ - public function updateTransfersFromOrders(array $existingTransfers, array $orders, array $pendingDebits) + private function getInvoiceAmount(array $invoice,MiraklClient $mclient ): int { - $updated = []; - foreach ($existingTransfers as $orderId => $transfer) { - $pendingDebit = $pendingDebits[$orderId] ?? null; - if (strpos($orderId, $_ENV['TAX_ORDER_POSTFIX']) !== false) { - $tax_suffixed_orderId = $orderId; - $orderId = str_replace($_ENV['TAX_ORDER_POSTFIX'], "", $orderId); - $pendingDebit = $pendingDebits[$orderId] ?? null; - $updated[$tax_suffixed_orderId] = $this->stripeTransferFactory->updateFromOrder( - $transfer, - $orders[$orderId], - $pendingDebit, - true - ); - } else { - $updated[$orderId] = $this->stripeTransferFactory->updateFromOrder( - $transfer, - $orders[$orderId], - $pendingDebit - ); - } + + //echo "\nccccccccccc".$invoice['invoice_id']; + $amount = $invoice['summary']['amount_transferred'] ?? 0; + $transactions = $mclient->getTransactionsForInvoce($invoice['invoice_id']); + + $total_tax = $this->findTotalOrderTax($transactions); + + // echo "\n\n".$total_tax; + + $amount = $amount - $total_tax; + // echo "\n".$amount; + + $amount = gmp_intval((string) ($amount * 100)); + if ($amount <= 0) { + throw new InvalidArgumentException(sprintf( + StripePayout::PAYOUT_STATUS_REASON_INVALID_AMOUNT, + $amount + )); } - // Save - $this->stripeTransferRepository->flush(); + return $amount; + } + + /** + * @param StripePayout $payout + * @param string $reason + * @return StripePayout + */ + private function putPayoutOnHold(StripePayout $payout, string $reason): StripePayout + { + $this->logger->info( + 'Payout on hold: ' . $reason, + ['invoice_id' => $payout->getMiraklInvoiceId()] + ); + + $payout->setStatusReason($reason); + return $payout->setStatus(StripePayout::PAYOUT_ON_HOLD); + } + + /** + * @param StripePayout $payout + * @param string $reason + * @return StripePayout + */ + private function abortPayout(StripePayout $payout, string $reason): StripePayout + { + $this->logger->info( + 'Payout aborted: ' . $reason, + ['invoice_id' => $payout->getMiraklInvoiceId()] + ); - return $updated; + $payout->setStatusReason($reason); + return $payout->setStatus(StripePayout::PAYOUT_ABORTED); + } + + /** + * @param StripePayout $payout + * @return StripePayout + */ + private function markPayoutAsCreated(StripePayout $payout): StripePayout + { + $this->logger->info( + 'Payout created', + ['invoice_id' => $payout->getMiraklInvoiceId()] + ); + + $payout->setStatusReason(null); + return $payout->setStatus(StripePayout::PAYOUT_CREATED); + } + + private function findTotalOrderTax($transactions) { + $taxes=0; + foreach ($transactions as $trx) { + if($trx['type']=='ORDER_AMOUNT_TAX'){ + $taxes += (float) $trx['amount']; + } + } + // echo "\n".$taxes; + return $taxes; + } } From 8a3de79d88d2fd12c23ebf4fa014a7b4632d6086 Mon Sep 17 00:00:00 2001 From: Tejpal Singh Date: Tue, 24 Jan 2023 12:03:26 +0530 Subject: [PATCH 26/40] remove comments & rund php fixer --- src/Factory/StripePayoutFactory.php | 35 +++++++++++------------------ 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/src/Factory/StripePayoutFactory.php b/src/Factory/StripePayoutFactory.php index ef3fe0e4..0543de32 100644 --- a/src/Factory/StripePayoutFactory.php +++ b/src/Factory/StripePayoutFactory.php @@ -18,7 +18,7 @@ class StripePayoutFactory implements LoggerAwareInterface * @var AccountMappingRepository */ private $accountMappingRepository; - + /** * @var MiraklClient */ @@ -33,7 +33,7 @@ public function __construct( * @param array $invoice * @return StripePayout */ - public function createFromInvoice(array $invoice,MiraklClient $mclient): StripePayout + public function createFromInvoice(array $invoice, MiraklClient $mclient): StripePayout { $payout = new StripePayout(); $payout->setMiraklInvoiceId($invoice['invoice_id']); @@ -41,7 +41,7 @@ public function createFromInvoice(array $invoice,MiraklClient $mclient): StripeP MiraklClient::getDatetimeFromString($invoice['date_created']) ); - return $this->updateFromInvoice($payout, $invoice,$mclient); + return $this->updateFromInvoice($payout, $invoice, $mclient); } /** @@ -49,7 +49,7 @@ public function createFromInvoice(array $invoice,MiraklClient $mclient): StripeP * @param array $invoice * @return StripePayout */ - public function updateFromInvoice(StripePayout $payout, array $invoice,MiraklClient $mclient): StripePayout + public function updateFromInvoice(StripePayout $payout, array $invoice, MiraklClient $mclient): StripePayout { // Payout already created if ($payout->getPayoutId()) { @@ -58,7 +58,7 @@ public function updateFromInvoice(StripePayout $payout, array $invoice,MiraklCli // Amount and currency try { - $payout->setAmount($this->getInvoiceAmount($invoice,$mclient)); + $payout->setAmount($this->getInvoiceAmount($invoice, $mclient)); $payout->setCurrency(strtolower($invoice['currency_iso_code'])); } catch (InvalidArgumentException $e) { return $this->abortPayout($payout, $e->getMessage()); @@ -122,20 +122,12 @@ private function getAccountMapping(int $shopId): AccountMapping * @param array $invoice * @return int */ - private function getInvoiceAmount(array $invoice,MiraklClient $mclient ): int + private function getInvoiceAmount(array $invoice, MiraklClient $mclient): int { - - //echo "\nccccccccccc".$invoice['invoice_id']; $amount = $invoice['summary']['amount_transferred'] ?? 0; - $transactions = $mclient->getTransactionsForInvoce($invoice['invoice_id']); - - $total_tax = $this->findTotalOrderTax($transactions); - - // echo "\n\n".$total_tax; - - $amount = $amount - $total_tax; - // echo "\n".$amount; - + $transactions = $mclient->getTransactionsForInvoce($invoice['invoice_id']); + $total_tax = $this->findTotalOrderTax($transactions); + $amount = $amount - $total_tax; $amount = gmp_intval((string) ($amount * 100)); if ($amount <= 0) { throw new InvalidArgumentException(sprintf( @@ -193,16 +185,15 @@ private function markPayoutAsCreated(StripePayout $payout): StripePayout $payout->setStatusReason(null); return $payout->setStatus(StripePayout::PAYOUT_CREATED); } - - private function findTotalOrderTax($transactions) { + + private function findTotalOrderTax($transactions) + { $taxes=0; foreach ($transactions as $trx) { - if($trx['type']=='ORDER_AMOUNT_TAX'){ + if ($trx['type']=='ORDER_AMOUNT_TAX') { $taxes += (float) $trx['amount']; } } - // echo "\n".$taxes; return $taxes; - } } From 3800bebd5fb77f9e35b9f1618959b68e372259ed Mon Sep 17 00:00:00 2001 From: Tejpal Singh Date: Tue, 24 Jan 2023 17:00:07 +0530 Subject: [PATCH 27/40] Fix the PHP errors given in build --- src/Entity/StripeTransfer.php | 2 ++ src/Factory/StripeTransferFactory.php | 27 ++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/Entity/StripeTransfer.php b/src/Entity/StripeTransfer.php index ded78afe..5f775846 100644 --- a/src/Entity/StripeTransfer.php +++ b/src/Entity/StripeTransfer.php @@ -45,6 +45,7 @@ class StripeTransfer public const TRANSFER_STATUS_REASON_REFUND_NOT_FOUND = 'Cannot find StripeRefund with ID %s'; public const TRANSFER_STATUS_REASON_REFUND_NOT_VALIDATED = 'Refund %s has yet to be validated'; public const TRANSFER_STATUS_REASON_TRANSFER_NOT_READY = 'Payment split has to occur before the transfer can be reversed for a refund'; + public const TRANSFER_STATUS_REASON_ACCOUNT_NOT_FOUND = 'Cannot find Stripe account for ID %s'; // Transfer status reasons: aborted public const TRANSFER_STATUS_REASON_ORDER_ABORTED = 'Order cannot be processed, status is %s'; @@ -54,6 +55,7 @@ class StripeTransfer public const TRANSFER_STATUS_REASON_PAYMENT_REFUNDED = 'Payment %s has been fully refunded'; public const TRANSFER_STATUS_REASON_NO_SHOP_ID = 'No shop ID provided'; public const TRANSFER_STATUS_REASON_ORDER_REFUND_ABORTED = 'Refund %s has been aborted'; + public const TRANSFER_STATUS_REASON_NO_ACCOUNT_ID = 'No stripe account ID provided'; // Transfer types public const TRANSFER_PRODUCT_ORDER = 'TRANSFER_PRODUCT_ORDER'; diff --git a/src/Factory/StripeTransferFactory.php b/src/Factory/StripeTransferFactory.php index feee9187..5576d495 100644 --- a/src/Factory/StripeTransferFactory.php +++ b/src/Factory/StripeTransferFactory.php @@ -125,7 +125,7 @@ public function updateFromOrder(StripeTransfer $transfer, MiraklOrder $order, Mi if (!$isForTax) { $accountMapping = $this->getAccountMapping($order->getShopId()); } else { - $accountMapping = $this->accountMappingRepository->findOneByStripeAccountId($_ENV['STRIPE_TAX_ACCOUNT']); + $accountMapping = $this->getAccountMappingByAccountId($_ENV['STRIPE_TAX_ACCOUNT']); } $transfer->setAccountMapping($accountMapping); } catch (InvalidArgumentException $e) { @@ -621,4 +621,29 @@ private function markTransferAsCreated(StripeTransfer $transfer): StripeTransfer ->setStatus(StripeTransfer::TRANSFER_CREATED) ->setStatusReason(null); } + + /** + * @param string $stripeAccountId + * @return AccountMapping + */ + private function getAccountMappingByAccountId(string $stripeAccountId): AccountMapping + { + if (!$stripeAccountId) { + throw new InvalidArgumentException( + StripeTransfer::TRANSFER_STATUS_REASON_NO_ACCOUNT_ID, + 10 + ); + } + + $mapping = $this->accountMappingRepository->findOneByStripeAccountId($stripeAccountId); + + if (!$mapping) { + throw new InvalidArgumentException(sprintf( + StripeTransfer::TRANSFER_STATUS_REASON_ACCOUNT_NOT_FOUND, + $stripeAccountId + ), 20); + } + + return $mapping; + } } From e0f5ec310b1c96154a617881f0fa2a71472ea13b Mon Sep 17 00:00:00 2001 From: Tejpal Singh Date: Wed, 1 Feb 2023 08:38:01 +0530 Subject: [PATCH 28/40] initial --- config/services.yaml | 8 +++++++ config/services_test.yaml | 1 + src/Entity/MiraklProductOrder.php | 2 +- src/Factory/StripePayoutFactory.php | 17 ++++++++------- src/Factory/StripeTransferFactory.php | 18 ++++++++++------ src/Service/MiraklClient.php | 9 +++++--- src/Service/PaymentRefundService.php | 6 ++++-- src/Service/PaymentSplitService.php | 21 ++++++++++++++----- src/Service/SellerSettlementService.php | 6 +++--- tests/Factory/StripePayoutFactoryTest.php | 2 +- tests/Factory/StripeTransferFactoryTest.php | 4 +++- tests/MiraklMockedHttpClient.php | 21 +++++++++++++++++++ tests/Service/PaymentRefundServiceTest.php | 7 +++++-- tests/Service/PaymentSplitServiceTest.php | 8 +++++-- tests/Service/SellerSettlementServiceTest.php | 7 +++++-- 15 files changed, 102 insertions(+), 35 deletions(-) diff --git a/config/services.yaml b/config/services.yaml index 5f67d873..b11f00bd 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -18,6 +18,8 @@ parameters: env(ENABLE_SERVICE_PAYMENT_SPLIT): false env(ENABLE_SERVICE_PAYMENT_REFUND): false env(ENABLE_SELLER_ONBOARDING): true + env(ENABLE_PAYMENT_TAX_SPLIT): false + env(STRIPE_TAX_ACCOUNT): "" default_redirect_onboarding: "%env(MIRAKL_HOST_NAME)%/mmp/shop/account/shop" default_enable_product_payment_split: false @@ -37,12 +39,14 @@ parameters: app.stripe.webhook_seller_secret: "%env(default:deprecated_webhook_secret:STRIPE_SELLERS_WEBHOOK_SECRET)%" app.stripe.webhook_operator_secret: "%env(default:deprecated_webhook_secret:STRIPE_OPERATOR_WEBHOOK_SECRET)%" app.stripe.prefill_onboarding: "%env(bool:STRIPE_PREFILL_ONBOARDING)%" + app.stripe.tax_account: "%env(STRIPE_TAX_ACCOUNT)%" app.workflow.enable_product_payment_split: "%env(default:deprecated_enable_product_payment_split:bool:ENABLE_PRODUCT_PAYMENT_SPLIT)%" app.workflow.enable_service_payment_split: "%env(bool:ENABLE_SERVICE_PAYMENT_SPLIT)%" app.workflow.enable_product_payment_refund: "%env(default:deprecated_enable_product_payment_refund:bool:ENABLE_PRODUCT_PAYMENT_REFUND)%" app.workflow.enable_service_payment_refund: "%env(bool:ENABLE_SERVICE_PAYMENT_REFUND)%" app.workflow.enable_seller_onboarding: "%env(bool:ENABLE_SELLER_ONBOARDING)%" app.workflow.payment_metadata_commercial_order_id: "%env(default:deprecated_payment_metadata_commercial_order_id:PAYMENT_METADATA_COMMERCIAL_ORDER_ID)%" + app.workflow.enable_payment_tax_split: "%env(bool:ENABLE_PAYMENT_TAX_SPLIT)%" app.mirakl.api_key: "%env(MIRAKL_API_KEY)%" app.mirakl.host_name: "%env(MIRAKL_HOST_NAME)%" app.mirakl.stripe_custom_field_code: "%env(MIRAKL_CUSTOM_FIELD_CODE)%" @@ -84,6 +88,10 @@ services: $technicalEmailFrom: "%app.mailer.technical_from%" $baseHostOverride: "%app.base_host%" + $enablePaymentTaxSplit: "%app.workflow.enable_payment_tax_split%" + $stripeTaxAccount: "%app.stripe.tax_account%" + $taxOrderPostfix: "_TAX" + # makes classes in src/ available to be used as services # this creates a service per class whose id is the fully-qualified class name App\: diff --git a/config/services_test.yaml b/config/services_test.yaml index 3d50ad4a..6305a08e 100644 --- a/config/services_test.yaml +++ b/config/services_test.yaml @@ -24,6 +24,7 @@ services: public: true arguments: $miraklClient: '@App\Tests\MiraklMockedHttpClient' + $taxOrderPostfix: 'string' App\Service\StripeClient: class: App\Service\StripeClient diff --git a/src/Entity/MiraklProductOrder.php b/src/Entity/MiraklProductOrder.php index 8cb2f19e..65ef67f4 100644 --- a/src/Entity/MiraklProductOrder.php +++ b/src/Entity/MiraklProductOrder.php @@ -130,7 +130,7 @@ public function getRefundedTax(StripeRefund $refund): float foreach ($line['refunds'] as $orderRefund) { if ($refund->getMiraklRefundId() === $orderRefund['id']) { $tax = $this->getRefundLineTaxes($orderRefund); - return $tax;//$orderRefund['commission_total_amount']; + return $tax; } } } diff --git a/src/Factory/StripePayoutFactory.php b/src/Factory/StripePayoutFactory.php index 0543de32..78fde215 100644 --- a/src/Factory/StripePayoutFactory.php +++ b/src/Factory/StripePayoutFactory.php @@ -22,18 +22,21 @@ class StripePayoutFactory implements LoggerAwareInterface /** * @var MiraklClient */ + private $mclient; public function __construct( - AccountMappingRepository $accountMappingRepository + AccountMappingRepository $accountMappingRepository, + MiraklClient $mclient ) { $this->accountMappingRepository = $accountMappingRepository; + $this->mclient = $mclient; } /** * @param array $invoice * @return StripePayout */ - public function createFromInvoice(array $invoice, MiraklClient $mclient): StripePayout + public function createFromInvoice(array $invoice): StripePayout { $payout = new StripePayout(); $payout->setMiraklInvoiceId($invoice['invoice_id']); @@ -41,7 +44,7 @@ public function createFromInvoice(array $invoice, MiraklClient $mclient): Stripe MiraklClient::getDatetimeFromString($invoice['date_created']) ); - return $this->updateFromInvoice($payout, $invoice, $mclient); + return $this->updateFromInvoice($payout, $invoice); } /** @@ -49,7 +52,7 @@ public function createFromInvoice(array $invoice, MiraklClient $mclient): Stripe * @param array $invoice * @return StripePayout */ - public function updateFromInvoice(StripePayout $payout, array $invoice, MiraklClient $mclient): StripePayout + public function updateFromInvoice(StripePayout $payout, array $invoice): StripePayout { // Payout already created if ($payout->getPayoutId()) { @@ -58,7 +61,7 @@ public function updateFromInvoice(StripePayout $payout, array $invoice, MiraklCl // Amount and currency try { - $payout->setAmount($this->getInvoiceAmount($invoice, $mclient)); + $payout->setAmount($this->getInvoiceAmount($invoice)); $payout->setCurrency(strtolower($invoice['currency_iso_code'])); } catch (InvalidArgumentException $e) { return $this->abortPayout($payout, $e->getMessage()); @@ -122,10 +125,10 @@ private function getAccountMapping(int $shopId): AccountMapping * @param array $invoice * @return int */ - private function getInvoiceAmount(array $invoice, MiraklClient $mclient): int + private function getInvoiceAmount(array $invoice): int { $amount = $invoice['summary']['amount_transferred'] ?? 0; - $transactions = $mclient->getTransactionsForInvoce($invoice['invoice_id']); + $transactions = $this->mclient->getTransactionsForInvoce($invoice['invoice_id']); $total_tax = $this->findTotalOrderTax($transactions); $amount = $amount - $total_tax; $amount = gmp_intval((string) ($amount * 100)); diff --git a/src/Factory/StripeTransferFactory.php b/src/Factory/StripeTransferFactory.php index 5576d495..b18d02a9 100644 --- a/src/Factory/StripeTransferFactory.php +++ b/src/Factory/StripeTransferFactory.php @@ -56,13 +56,17 @@ class StripeTransferFactory implements LoggerAwareInterface */ private $stripeClient; + private $stripeTaxAccount; + private $taxOrderPostfix; public function __construct( AccountMappingRepository $accountMappingRepository, PaymentMappingRepository $paymentMappingRepository, StripeRefundRepository $stripeRefundRepository, StripeTransferRepository $stripeTransferRepository, MiraklClient $miraklClient, - StripeClient $stripeClient + StripeClient $stripeClient, + string $stripeTaxAccount, + string $taxOrderPostfix ) { $this->accountMappingRepository = $accountMappingRepository; $this->paymentMappingRepository = $paymentMappingRepository; @@ -70,6 +74,8 @@ public function __construct( $this->stripeTransferRepository = $stripeTransferRepository; $this->miraklClient = $miraklClient; $this->stripeClient = $stripeClient; + $this->stripeTaxAccount = $stripeTaxAccount; + $this->taxOrderPostfix = $taxOrderPostfix; } /** @@ -102,7 +108,7 @@ public function createFromOrderForTax(MiraklOrder $order, MiraklPendingDebit $pe $transfer = new StripeTransfer(); $transfer->setType($type); - $transfer->setMiraklId($order->getId().$_ENV['TAX_ORDER_POSTFIX']); + $transfer->setMiraklId($order->getId().$this->taxOrderPostfix); $transfer->setMiraklCreatedDate($order->getCreationDateAsDateTime()); return $this->updateFromOrder($transfer, $order, $pendingDebit, true); @@ -125,7 +131,7 @@ public function updateFromOrder(StripeTransfer $transfer, MiraklOrder $order, Mi if (!$isForTax) { $accountMapping = $this->getAccountMapping($order->getShopId()); } else { - $accountMapping = $this->getAccountMappingByAccountId($_ENV['STRIPE_TAX_ACCOUNT']); + $accountMapping = $this->getAccountMappingByAccountId($this->stripeTaxAccount); } $transfer->setAccountMapping($accountMapping); } catch (InvalidArgumentException $e) { @@ -252,7 +258,7 @@ public function createFromOrderRefundForTax(MiraklPendingRefund $orderRefund): S { $transfer = new StripeTransfer(); $transfer->setType(StripeTransfer::TRANSFER_REFUND); - $transfer->setMiraklId($orderRefund->getId().$_ENV['TAX_ORDER_POSTFIX']); + $transfer->setMiraklId($orderRefund->getId().$this->taxOrderPostfix); return $this->updateOrderRefundTransfer($transfer, true); } @@ -271,12 +277,12 @@ public function updateOrderRefundTransfer(StripeTransfer $transfer, $isForTax = // Check corresponding StripeRefund $refund = null; try { - $refund = $this->findRefundFromRefundId(str_replace($_ENV['TAX_ORDER_POSTFIX'], "", $transfer->getMiraklId())); + $refund = $this->findRefundFromRefundId(str_replace($this->taxOrderPostfix, "", $transfer->getMiraklId())); // Fetch transfer to be reversed $orderIds = [$refund->getMiraklOrderId()]; if ($isForTax) { - $orderIds = [$refund->getMiraklOrderId().$_ENV['TAX_ORDER_POSTFIX']]; + $orderIds = [$refund->getMiraklOrderId().$this->taxOrderPostfix]; } $orderTransfer = current($this->stripeTransferRepository->findTransfersByOrderIds($orderIds)); diff --git a/src/Service/MiraklClient.php b/src/Service/MiraklClient.php index c87d48d0..71094908 100644 --- a/src/Service/MiraklClient.php +++ b/src/Service/MiraklClient.php @@ -28,9 +28,12 @@ class MiraklClient */ private $client; - public function __construct(HttpClientInterface $miraklClient) + private $taxOrderPostfix; + + public function __construct(HttpClientInterface $miraklClient, string $taxOrderPostfix) { $this->client = $miraklClient; + $this->taxOrderPostfix = $taxOrderPostfix; } private function get(string $endpoint, array $params = []): ResponseInterface @@ -391,8 +394,8 @@ public static function getStringFromDatetime(\DateTimeInterface $date): string return $date->format(self::DATE_FORMAT); } - private function removeTaxKeword($val) + private function removeTaxKeword($val): string { - return str_replace($_ENV['TAX_ORDER_POSTFIX'], "", $val); + return str_replace($this->taxOrderPostfix, "", $val); } } diff --git a/src/Service/PaymentRefundService.php b/src/Service/PaymentRefundService.php index 5ab09050..a5d59767 100644 --- a/src/Service/PaymentRefundService.php +++ b/src/Service/PaymentRefundService.php @@ -34,12 +34,14 @@ public function __construct( StripeRefundFactory $stripeRefundFactory, StripeTransferFactory $stripeTransferFactory, StripeRefundRepository $stripeRefundRepository, - StripeTransferRepository $stripeTransferRepository + StripeTransferRepository $stripeTransferRepository, + string $taxOrderPostfix ) { $this->stripeRefundFactory = $stripeRefundFactory; $this->stripeTransferFactory = $stripeTransferFactory; $this->stripeRefundRepository = $stripeRefundRepository; $this->stripeTransferRepository = $stripeTransferRepository; + $this->taxOrderPostfix = $taxOrderPostfix; } /** @@ -134,7 +136,7 @@ public function updateTransfers(array $transfers): array { $updated = []; foreach ($transfers as $refundId => $transfer) { - if (strpos($refundId, $_ENV['TAX_ORDER_POSTFIX']) !== false) { + if (strpos($refundId, $this->taxOrderPostfix) !== false) { $updated[$refundId] = $this->stripeTransferFactory->updateOrderRefundTransfer($transfer, true); } else { $updated[$refundId] = $this->stripeTransferFactory->updateOrderRefundTransfer($transfer); diff --git a/src/Service/PaymentSplitService.php b/src/Service/PaymentSplitService.php index c3ee9ba0..83f78ed2 100644 --- a/src/Service/PaymentSplitService.php +++ b/src/Service/PaymentSplitService.php @@ -2,6 +2,7 @@ namespace App\Service; +use App\Service\MiraklClient; use App\Factory\StripeTransferFactory; use App\Repository\StripeTransferRepository; @@ -17,12 +18,20 @@ class PaymentSplitService */ private $stripeTransferRepository; + private $enablePaymentTaxSplit; + private $taxOrderPostfix; + public function __construct( StripeTransferFactory $stripeTransferFactory, - StripeTransferRepository $stripeTransferRepository + StripeTransferRepository $stripeTransferRepository, + MiraklClient $miraklClient, + bool $enablePaymentTaxSplit, + string $taxOrderPostfix, ) { $this->stripeTransferFactory = $stripeTransferFactory; $this->stripeTransferRepository = $stripeTransferRepository; + $this->enablePaymentTaxSplit = $enablePaymentTaxSplit; + $this->taxOrderPostfix = $taxOrderPostfix; } /** @@ -66,8 +75,10 @@ public function getTransfersFromOrders(array $orders, array $pendingDebits): arr // Create new transfer $transfer = $this->stripeTransferFactory->createFromOrder($order, $pendingDebit); $this->stripeTransferRepository->persist($transfer); - $tax_transfer = $this->stripeTransferFactory->createFromOrderForTax($order, $pendingDebit); - $this->stripeTransferRepository->persist($tax_transfer); + if ($this->enablePaymentTaxSplit) { + $tax_transfer = $this->stripeTransferFactory->createFromOrderForTax($order, $pendingDebit); + $this->stripeTransferRepository->persist($tax_transfer); + } } $transfers[] = $transfer; @@ -92,9 +103,9 @@ public function updateTransfersFromOrders(array $existingTransfers, array $order $updated = []; foreach ($existingTransfers as $orderId => $transfer) { $pendingDebit = $pendingDebits[$orderId] ?? null; - if (strpos($orderId, $_ENV['TAX_ORDER_POSTFIX']) !== false) { + if ($this->enablePaymentTaxSplit && strpos($orderId, $this->taxOrderPostfix) !== false) { $tax_suffixed_orderId = $orderId; - $orderId = str_replace($_ENV['TAX_ORDER_POSTFIX'], "", $orderId); + $orderId = str_replace($this->taxOrderPostfix, "", $orderId); $pendingDebit = $pendingDebits[$orderId] ?? null; $updated[$tax_suffixed_orderId] = $this->stripeTransferFactory->updateFromOrder( $transfer, diff --git a/src/Service/SellerSettlementService.php b/src/Service/SellerSettlementService.php index 245450f3..6309771c 100644 --- a/src/Service/SellerSettlementService.php +++ b/src/Service/SellerSettlementService.php @@ -136,7 +136,7 @@ public function getRetriablePayouts(): array * @param array $invoices * @return array StripePayout[] */ - public function getPayoutsFromInvoices(array $invoices, MiraklClient $mclient): array + public function getPayoutsFromInvoices(array $invoices): array { // Retrieve existing StripeTransfers with provided invoice IDs $existingPayouts = $this->stripePayoutRepository @@ -153,11 +153,11 @@ public function getPayoutsFromInvoices(array $invoices, MiraklClient $mclient): // Use existing payout $payout = $this->stripePayoutFactory - ->updateFromInvoice($payout, $invoice, $mclient); + ->updateFromInvoice($payout, $invoice); } else { // Create new payout $payout = $this->stripePayoutFactory - ->createFromInvoice($invoice, $mclient); + ->createFromInvoice($invoice); $this->stripePayoutRepository->persist($payout); } diff --git a/tests/Factory/StripePayoutFactoryTest.php b/tests/Factory/StripePayoutFactoryTest.php index e30555ed..c01e5183 100644 --- a/tests/Factory/StripePayoutFactoryTest.php +++ b/tests/Factory/StripePayoutFactoryTest.php @@ -37,7 +37,7 @@ protected function setUp(): void $this->stripePayoutFactory = new StripePayoutFactory( $container->get('doctrine')->getRepository(AccountMapping::class), - $container->get('App\Service\StripeClient') + $container->get('App\Service\MiraklClient') ); $this->stripePayoutFactory->setLogger(new NullLogger()); } diff --git a/tests/Factory/StripeTransferFactoryTest.php b/tests/Factory/StripeTransferFactoryTest.php index fc197d31..b5bdd997 100644 --- a/tests/Factory/StripeTransferFactoryTest.php +++ b/tests/Factory/StripeTransferFactoryTest.php @@ -62,7 +62,9 @@ protected function setUp(): void $this->stripeRefundRepository, $this->stripeTransferRepository, $this->miraklClient, - $container->get('App\Service\StripeClient') + $container->get('App\Service\StripeClient'), + 'acc_xxxxxxx', + '_TAX' ); $this->stripeTransferFactory->setLogger(new NullLogger()); } diff --git a/tests/MiraklMockedHttpClient.php b/tests/MiraklMockedHttpClient.php index 26c1ebe0..761c408b 100644 --- a/tests/MiraklMockedHttpClient.php +++ b/tests/MiraklMockedHttpClient.php @@ -331,6 +331,16 @@ private function mockResponse(string $method, string $path, array $params, ?arra return ['invoices' => []]; } break; + case '/api/sellerpayment/transactions_logs': + switch (true) { + case isset($params['accounting_document_number']): + $doc_number = $params['accounting_document_number']; + $max = $params['max']; + return ['data' => $this->mockTransactionsLogsByDocumentNumber($doc_number, $max)]; + default: + return ['data' => []]; + } + break; } throw new InvalidArgumentException(); @@ -1130,4 +1140,15 @@ private function getInvoice($invoiceId, $shopId = self::SHOP_BASIC) ], ]; } + + private function mockTransactionsLogsByDocumentNumber() + { + return [ + [ + 'id' => rand(1, 1000), + 'type' => 'ORDER_AMOUNT_TAX', + 'amount' => 100, + ], + ]; + } } diff --git a/tests/Service/PaymentRefundServiceTest.php b/tests/Service/PaymentRefundServiceTest.php index 53f61cc4..2e75b440 100644 --- a/tests/Service/PaymentRefundServiceTest.php +++ b/tests/Service/PaymentRefundServiceTest.php @@ -72,7 +72,9 @@ protected function setUp(): void $this->stripeRefundRepository, $this->stripeTransferRepository, $this->miraklClient, - $stripeClient + $stripeClient, + '', + '' ); $stripeTransferFactory->setLogger(new NullLogger()); @@ -80,7 +82,8 @@ protected function setUp(): void $stripeRefundFactory, $stripeTransferFactory, $this->stripeRefundRepository, - $this->stripeTransferRepository + $this->stripeTransferRepository, + '_TAX' ); } diff --git a/tests/Service/PaymentSplitServiceTest.php b/tests/Service/PaymentSplitServiceTest.php index 55d9b816..e0772322 100644 --- a/tests/Service/PaymentSplitServiceTest.php +++ b/tests/Service/PaymentSplitServiceTest.php @@ -51,14 +51,18 @@ protected function setUp(): void $container->get('doctrine')->getRepository(StripeRefund::class), $this->stripeTransferRepository, $this->miraklClient, - $container->get('App\Service\StripeClient') + $container->get('App\Service\StripeClient'), + 'acc_xxxxxxx', + '_TAX' ); $stripeTransferFactory->setLogger(new NullLogger()); $this->paymentSplitService = new PaymentSplitService( $stripeTransferFactory, $this->stripeTransferRepository, - $this->miraklClient + $this->miraklClient, + false, + '_TAX' ); } diff --git a/tests/Service/SellerSettlementServiceTest.php b/tests/Service/SellerSettlementServiceTest.php index f3d9eb9a..4c2008bd 100644 --- a/tests/Service/SellerSettlementServiceTest.php +++ b/tests/Service/SellerSettlementServiceTest.php @@ -59,12 +59,15 @@ protected function setUp(): void $container->get('doctrine')->getRepository(StripeRefund::class), $this->stripeTransferRepository, $this->miraklClient, - $container->get('App\Service\StripeClient') + $container->get('App\Service\StripeClient'), + 'acc_xxxxxxx', + '_TAX' ); $stripeTransferFactory->setLogger(new NullLogger()); $stripePayoutFactory = new StripePayoutFactory( - $container->get('doctrine')->getRepository(AccountMapping::class) + $container->get('doctrine')->getRepository(AccountMapping::class), + $this->miraklClient ); $stripePayoutFactory->setLogger(new NullLogger()); From ddb0c57db0c08989e83647dbf946f1c9e3fc65e4 Mon Sep 17 00:00:00 2001 From: Tejpal Singh Date: Thu, 2 Feb 2023 11:37:10 +0530 Subject: [PATCH 29/40] change --- tests/Service/PaymentRefundServiceTest.php | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/Service/PaymentRefundServiceTest.php b/tests/Service/PaymentRefundServiceTest.php index 2e75b440..651a4e7d 100644 --- a/tests/Service/PaymentRefundServiceTest.php +++ b/tests/Service/PaymentRefundServiceTest.php @@ -73,8 +73,8 @@ protected function setUp(): void $this->stripeTransferRepository, $this->miraklClient, $stripeClient, - '', - '' + 'acc_xxxxxxx', + '_TAX' ); $stripeTransferFactory->setLogger(new NullLogger()); @@ -157,14 +157,14 @@ private function getServiceTransfersFromRepository() public function testGetRetriableProductTransfers() { $orders = $this->miraklClient->listProductPendingRefunds(); - $this->mockOrderTransfer($orders[MiraklMock::PRODUCT_ORDER_REFUND_BASIC], StripeMock::CHARGE_BASIC); + $this->mockOrderTransfer($orders[MiraklMock::PRODUCT_ORDER_REFUND_BASIC], StripeMock::CHARGE_BASIC); $refunds = $this->paymentRefundService->getRefundsFromOrderRefunds($orders); $this->mockRefundCreated($this->getBasicProductRefundFromRepository()); $transfers = $this->paymentRefundService->getTransfersFromOrderRefunds($orders); - $this->assertCount(14, $transfers); - $this->assertCount(14, $this->getProductTransfersFromRepository()); + $this->assertCount(28, $transfers); + $this->assertCount(28, $this->getProductTransfersFromRepository()); // All except ORDER_REFUND_BASIC are retriable $this->assertCount(13, $this->paymentRefundService->getRetriableTransfers()); @@ -174,7 +174,7 @@ public function testGetRetriableProductTransfers() public function testGetTransfersFromProductOrders() { $orders = $this->miraklClient->listProductPendingRefunds(); - $this->mockOrderTransfer($orders[MiraklMock::PRODUCT_ORDER_REFUND_BASIC], StripeMock::CHARGE_BASIC); + $this->mockOrderTransfer($orders[MiraklMock::PRODUCT_ORDER_REFUND_BASIC], StripeMock::CHARGE_BASIC); $refunds = $this->paymentRefundService->getRefundsFromOrderRefunds($orders); $this->mockRefundCreated($this->getBasicProductRefundFromRepository()); @@ -192,7 +192,7 @@ public function testGetTransfersFromProductOrders() public function testGetRefundsFromProductOrders() { $orders = $this->miraklClient->listProductPendingRefunds(); - $this->mockOrderTransfer($orders[MiraklMock::PRODUCT_ORDER_REFUND_BASIC], StripeMock::CHARGE_BASIC); + $this->mockOrderTransfer($orders[MiraklMock::PRODUCT_ORDER_REFUND_BASIC], StripeMock::CHARGE_BASIC); $refunds = $this->paymentRefundService->getRefundsFromOrderRefunds($orders); $this->mockRefundCreated($this->getBasicProductRefundFromRepository()); @@ -206,7 +206,7 @@ public function testGetRefundsFromProductOrders() public function testUpdateProductTransfers() { $orders = $this->miraklClient->listProductPendingRefunds(); - $this->mockOrderTransfer($orders[MiraklMock::PRODUCT_ORDER_REFUND_BASIC], StripeMock::CHARGE_BASIC); + $this->mockOrderTransfer($orders[MiraklMock::PRODUCT_ORDER_REFUND_BASIC], StripeMock::CHARGE_BASIC); $refunds = $this->paymentRefundService->getRefundsFromOrderRefunds($orders); $this->assertCount(14, $refunds); @@ -230,7 +230,7 @@ public function testUpdateProductTransfers() public function testGetRetriableServiceTransfers() { $orders = $this->miraklClient->listServicePendingRefunds(); - $this->mockOrderTransfer($orders[MiraklMock::SERVICE_ORDER_REFUND_BASIC], StripeMock::CHARGE_BASIC); + $this->mockOrderTransfer($orders[MiraklMock::SERVICE_ORDER_REFUND_BASIC], StripeMock::CHARGE_BASIC); $refunds = $this->paymentRefundService->getRefundsFromOrderRefunds($orders); $this->mockRefundCreated($this->getBasicServiceRefundFromRepository()); @@ -247,7 +247,7 @@ public function testGetRetriableServiceTransfers() public function testGetTransfersFromServiceOrders() { $orders = $this->miraklClient->listServicePendingRefunds(); - $this->mockOrderTransfer($orders[MiraklMock::SERVICE_ORDER_REFUND_BASIC], StripeMock::CHARGE_BASIC); + $this->mockOrderTransfer($orders[MiraklMock::SERVICE_ORDER_REFUND_BASIC], StripeMock::CHARGE_BASIC); $refunds = $this->paymentRefundService->getRefundsFromOrderRefunds($orders); $this->mockRefundCreated($this->getBasicServiceRefundFromRepository()); @@ -265,7 +265,7 @@ public function testGetTransfersFromServiceOrders() public function testGetRefundsFromServiceOrders() { $orders = $this->miraklClient->listServicePendingRefunds(); - $this->mockOrderTransfer($orders[MiraklMock::SERVICE_ORDER_REFUND_BASIC], StripeMock::CHARGE_BASIC); + $this->mockOrderTransfer($orders[MiraklMock::SERVICE_ORDER_REFUND_BASIC], StripeMock::CHARGE_BASIC); $refunds = $this->paymentRefundService->getRefundsFromOrderRefunds($orders); $this->mockRefundCreated($this->getBasicServiceRefundFromRepository()); @@ -279,7 +279,7 @@ public function testGetRefundsFromServiceOrders() public function testUpdateServiceTransfers() { $orders = $this->miraklClient->listServicePendingRefunds(); - $this->mockOrderTransfer($orders[MiraklMock::SERVICE_ORDER_REFUND_BASIC], StripeMock::CHARGE_BASIC); + $this->mockOrderTransfer($orders[MiraklMock::SERVICE_ORDER_REFUND_BASIC], StripeMock::CHARGE_BASIC); $refunds = $this->paymentRefundService->getRefundsFromOrderRefunds($orders); $this->assertCount(14, $refunds); From 4d6959a863fd4d5f7e9aabdc5cafa48cd87decba Mon Sep 17 00:00:00 2001 From: Tejpal Singh Date: Thu, 2 Feb 2023 11:39:42 +0530 Subject: [PATCH 30/40] change --- tests/Command/SellerSettlementCommandTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Command/SellerSettlementCommandTest.php b/tests/Command/SellerSettlementCommandTest.php index 5c992b65..2d0761d5 100644 --- a/tests/Command/SellerSettlementCommandTest.php +++ b/tests/Command/SellerSettlementCommandTest.php @@ -125,6 +125,7 @@ public function testByShopId() // 1 payout and 3 transfers dispatched $this->assertCount(3, $this->transfersReceiver->getSent()); $this->assertCount(3, $this->getTransfersFromRepository()); + print_r($this->payoutsReceiver->getSent()); $this->assertCount(1, $this->payoutsReceiver->getSent()); $this->assertCount(1, $this->getPayoutsFromRepository()); From 35aeb788cadd9c09b48e8853fdb64109796370bd Mon Sep 17 00:00:00 2001 From: Tejpal Singh Date: Thu, 2 Feb 2023 12:36:42 +0530 Subject: [PATCH 31/40] remove commnet --- tests/Command/SellerSettlementCommandTest.php | 1 - tests/Factory/StripePayoutFactoryTest.php | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/Command/SellerSettlementCommandTest.php b/tests/Command/SellerSettlementCommandTest.php index 2d0761d5..5c992b65 100644 --- a/tests/Command/SellerSettlementCommandTest.php +++ b/tests/Command/SellerSettlementCommandTest.php @@ -125,7 +125,6 @@ public function testByShopId() // 1 payout and 3 transfers dispatched $this->assertCount(3, $this->transfersReceiver->getSent()); $this->assertCount(3, $this->getTransfersFromRepository()); - print_r($this->payoutsReceiver->getSent()); $this->assertCount(1, $this->payoutsReceiver->getSent()); $this->assertCount(1, $this->getPayoutsFromRepository()); diff --git a/tests/Factory/StripePayoutFactoryTest.php b/tests/Factory/StripePayoutFactoryTest.php index c01e5183..5b6bd504 100644 --- a/tests/Factory/StripePayoutFactoryTest.php +++ b/tests/Factory/StripePayoutFactoryTest.php @@ -36,8 +36,7 @@ protected function setUp(): void $this->miraklClient = $container->get('App\Service\MiraklClient'); $this->stripePayoutFactory = new StripePayoutFactory( - $container->get('doctrine')->getRepository(AccountMapping::class), - $container->get('App\Service\MiraklClient') + $container->get('doctrine')->getRepository(AccountMapping::class) ); $this->stripePayoutFactory->setLogger(new NullLogger()); } From a10970f876c9c78631cacc57f1936a645281be2e Mon Sep 17 00:00:00 2001 From: Tejpal Singh Date: Thu, 2 Feb 2023 13:05:52 +0530 Subject: [PATCH 32/40] changes --- src/Factory/StripePayoutFactory.php | 17 +++++++---------- src/Service/SellerSettlementService.php | 6 +++--- tests/Factory/StripePayoutFactoryTest.php | 9 +++++---- tests/Service/SellerSettlementServiceTest.php | 8 ++++---- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/Factory/StripePayoutFactory.php b/src/Factory/StripePayoutFactory.php index 78fde215..0543de32 100644 --- a/src/Factory/StripePayoutFactory.php +++ b/src/Factory/StripePayoutFactory.php @@ -22,21 +22,18 @@ class StripePayoutFactory implements LoggerAwareInterface /** * @var MiraklClient */ - private $mclient; public function __construct( - AccountMappingRepository $accountMappingRepository, - MiraklClient $mclient + AccountMappingRepository $accountMappingRepository ) { $this->accountMappingRepository = $accountMappingRepository; - $this->mclient = $mclient; } /** * @param array $invoice * @return StripePayout */ - public function createFromInvoice(array $invoice): StripePayout + public function createFromInvoice(array $invoice, MiraklClient $mclient): StripePayout { $payout = new StripePayout(); $payout->setMiraklInvoiceId($invoice['invoice_id']); @@ -44,7 +41,7 @@ public function createFromInvoice(array $invoice): StripePayout MiraklClient::getDatetimeFromString($invoice['date_created']) ); - return $this->updateFromInvoice($payout, $invoice); + return $this->updateFromInvoice($payout, $invoice, $mclient); } /** @@ -52,7 +49,7 @@ public function createFromInvoice(array $invoice): StripePayout * @param array $invoice * @return StripePayout */ - public function updateFromInvoice(StripePayout $payout, array $invoice): StripePayout + public function updateFromInvoice(StripePayout $payout, array $invoice, MiraklClient $mclient): StripePayout { // Payout already created if ($payout->getPayoutId()) { @@ -61,7 +58,7 @@ public function updateFromInvoice(StripePayout $payout, array $invoice): StripeP // Amount and currency try { - $payout->setAmount($this->getInvoiceAmount($invoice)); + $payout->setAmount($this->getInvoiceAmount($invoice, $mclient)); $payout->setCurrency(strtolower($invoice['currency_iso_code'])); } catch (InvalidArgumentException $e) { return $this->abortPayout($payout, $e->getMessage()); @@ -125,10 +122,10 @@ private function getAccountMapping(int $shopId): AccountMapping * @param array $invoice * @return int */ - private function getInvoiceAmount(array $invoice): int + private function getInvoiceAmount(array $invoice, MiraklClient $mclient): int { $amount = $invoice['summary']['amount_transferred'] ?? 0; - $transactions = $this->mclient->getTransactionsForInvoce($invoice['invoice_id']); + $transactions = $mclient->getTransactionsForInvoce($invoice['invoice_id']); $total_tax = $this->findTotalOrderTax($transactions); $amount = $amount - $total_tax; $amount = gmp_intval((string) ($amount * 100)); diff --git a/src/Service/SellerSettlementService.php b/src/Service/SellerSettlementService.php index 6309771c..245450f3 100644 --- a/src/Service/SellerSettlementService.php +++ b/src/Service/SellerSettlementService.php @@ -136,7 +136,7 @@ public function getRetriablePayouts(): array * @param array $invoices * @return array StripePayout[] */ - public function getPayoutsFromInvoices(array $invoices): array + public function getPayoutsFromInvoices(array $invoices, MiraklClient $mclient): array { // Retrieve existing StripeTransfers with provided invoice IDs $existingPayouts = $this->stripePayoutRepository @@ -153,11 +153,11 @@ public function getPayoutsFromInvoices(array $invoices): array // Use existing payout $payout = $this->stripePayoutFactory - ->updateFromInvoice($payout, $invoice); + ->updateFromInvoice($payout, $invoice, $mclient); } else { // Create new payout $payout = $this->stripePayoutFactory - ->createFromInvoice($invoice); + ->createFromInvoice($invoice, $mclient); $this->stripePayoutRepository->persist($payout); } diff --git a/tests/Factory/StripePayoutFactoryTest.php b/tests/Factory/StripePayoutFactoryTest.php index 5b6bd504..747db7e9 100644 --- a/tests/Factory/StripePayoutFactoryTest.php +++ b/tests/Factory/StripePayoutFactoryTest.php @@ -46,7 +46,8 @@ public function testCreateFromInvoice() $payout = $this->stripePayoutFactory->createFromInvoice( current($this->miraklClient->listInvoicesByDate( MiraklMockedHttpClient::INVOICE_DATE_1_VALID - )) + )), + $this->miraklClient ); $this->assertEquals(StripePayout::PAYOUT_PENDING, $payout->getStatus()); @@ -66,7 +67,7 @@ public function testUpdateFromInvoice() )); $invoiceId = $invoice['invoice_id']; - $payout = $this->stripePayoutFactory->createFromInvoice($invoice); + $payout = $this->stripePayoutFactory->createFromInvoice($invoice, $this->miraklClient); $this->assertEquals(StripePayout::PAYOUT_ON_HOLD, $payout->getStatus()); $invoice = current($this->miraklClient->listInvoicesByDate( @@ -83,7 +84,7 @@ public function testInvalidInvoices() MiraklMockedHttpClient::INVOICE_DATE_3_INVOICES_ALL_INVALID ); foreach ($invoices as $invoiceId => $invoice) { - $payout = $this->stripePayoutFactory->createFromInvoice($invoice); + $payout = $this->stripePayoutFactory->createFromInvoice($invoice, $this->miraklClient); switch ($invoiceId) { case MiraklMockedHttpClient::INVOICE_INVALID_NO_SHOP: $this->assertEquals(StripePayout::PAYOUT_ABORTED, $payout->getStatus()); @@ -107,7 +108,7 @@ public function testInvoiceWithPayout() MiraklMockedHttpClient::INVOICE_DATE_1_VALID )); - $payout = $this->stripePayoutFactory->createFromInvoice($invoice); + $payout = $this->stripePayoutFactory->createFromInvoice($invoice, $this->miraklClient); $this->assertEquals(StripePayout::PAYOUT_PENDING, $payout->getStatus()); $payout->setPayoutId(StripeMockedHttpClient::PAYOUT_BASIC); diff --git a/tests/Service/SellerSettlementServiceTest.php b/tests/Service/SellerSettlementServiceTest.php index 4c2008bd..6df83eef 100644 --- a/tests/Service/SellerSettlementServiceTest.php +++ b/tests/Service/SellerSettlementServiceTest.php @@ -112,7 +112,7 @@ public function testGetRetriablePayouts() $invoices = $this->miraklClient->listInvoicesByDate( MiraklMockedHttpClient::INVOICE_DATE_3_INVOICES_1_VALID ); - $payouts = $this->sellerSettlementService->getPayoutsFromInvoices($invoices); + $payouts = $this->sellerSettlementService->getPayoutsFromInvoices($invoices, $this->miraklClient); $this->assertCount(3, $payouts); $payouts = $this->getPayoutsFromRepository(); @@ -144,10 +144,10 @@ public function testGetPayoutsFromInvoices() $invoices = $this->miraklClient->listInvoicesByDate( MiraklMockedHttpClient::INVOICE_DATE_3_INVOICES_1_VALID ); - $payouts = $this->sellerSettlementService->getPayoutsFromInvoices($invoices); + $payouts = $this->sellerSettlementService->getPayoutsFromInvoices($invoices, $this->miraklClient); $this->assertCount(3, $payouts); - $payouts = $this->sellerSettlementService->getPayoutsFromInvoices($invoices); + $payouts = $this->sellerSettlementService->getPayoutsFromInvoices($invoices, $this->miraklClient); // BASIC is already pending and AMOUNT_INVALID is aborted $this->assertCount(1, $payouts); @@ -183,7 +183,7 @@ public function testUpdatePayoutsFromInvoices() $invoices = $this->miraklClient->listInvoicesByDate( MiraklMockedHttpClient::INVOICE_DATE_3_INVOICES_1_VALID ); - $payouts = $this->sellerSettlementService->getPayoutsFromInvoices($invoices); + $payouts = $this->sellerSettlementService->getPayoutsFromInvoices($invoices, $this->miraklClient); $this->assertCount(3, $payouts); // Only INVALID_SHOP is retriable From bc49973140ee764fcdcfec134ed93f7b7ab21b06 Mon Sep 17 00:00:00 2001 From: Tejpal Singh Date: Thu, 2 Feb 2023 18:21:06 +0530 Subject: [PATCH 33/40] payment refund service test revert --- real.env | 173 +++++++++++++++++++++ tests/Service/PaymentRefundServiceTest.php | 4 +- 2 files changed, 175 insertions(+), 2 deletions(-) create mode 100644 real.env diff --git a/real.env b/real.env new file mode 100644 index 00000000..3ca20e26 --- /dev/null +++ b/real.env @@ -0,0 +1,173 @@ +########################### +###### Core Settings ###### +########################### + +# Should remain "prod" even when using your sandbox environment. +APP_ENV=prod + +# See https://symfony.com/doc/current/reference/configuration/framework.html#secret +# Required +#APP_SECRET=TO_BE_GENERATED +APP_SECRET=529190034a788e18fd95d6a8e30da739abfaea34 + +# Secret used to authenticate private calls. +# Will have to be in the X-AUTH-TOKEN header of every private request. Please generate a strong secret +#OPERATOR_PASSWORD=TO_BE_GENERATED +OPERATOR_PASSWORD=CMirakl@2022 + +# The scheme on which the connector will be publicly available. +# Used when generating refresh URLs for the onboarding flow. +# Defaults to https +#SCHEME=https + +# The base host on which the connector will be publicly available. +# Used when generating refresh URLs for the onboarding flow. +# Required +#BASE_HOST=stripe-mirakl.example.com +#BASE_HOST=cnetricin-dev.mirakl.net +BASE_HOST=stripe-dev.mirakl.net + +# If you use a proxy, tell Symfony which reverse proxy IP addresses to trust. +# See How to Configure Symfony to Work behind a Load Balancer or a Reverse Proxy: +# https://symfony.com/doc/4.4/deployment/proxies.html +#TRUSTED_PROXIES=127.0.0.1,REMOTE_ADDR + +# The connection URL to your database. +# See https://www.doctrine-project.org/projects/doctrine-dbal/en/2.9/reference/configuration.html#connecting-using-a-url +# Required +#DATABASE_URL=pgsql://symfony:symfony@db:5432/symfony?charset=UTF-8 +DATABASE_URL=pgsql://postgres:77453656@localhost:5432/smc_db_service?charset=UTF-8 + +# The transport used for the queuing system. +# See Symfony Messenger documentation for supported transports: +# https://symfony.com/doc/current/messenger.html#transports-async-queued-messages +# Example for RabbitMQ: amqp://guest:guest@localhost:5672/%2f/messages +# Default is doctrine://default +# Required +MESSENGER_TRANSPORT_DSN=doctrine://default + +# Your Stripe Client Secret. Available in your dashboard. +# https://dashboard.stripe.com/apikeys +# Required +#STRIPE_CLIENT_SECRET=sk_xxxx +STRIPE_CLIENT_SECRET=sk_test_51MHo4lIldRBoiz9oXERfpQhS6UipUYkx6GjRgskSvEuakxFyMScQdva9mb8XqoIuhaaPfre4wKxifa7XebxX6X7B00fKDfmYfO + + + +# Host name of your Mirakl Instance. Will be used as base for all Mirakl API calls. +# Required +#MIRAKL_HOST_NAME=https://mymarketplace.mirakl.net +MIRAKL_HOST_NAME=https://stripe-dev.mirakl.net + +# The Mirakl Operator key. Can be generated as a Mirakl operator +# Recommendation: create a specific operator for the connector. +# Generate the key on https://mymarketplace.mirakl.net/mmp/operator/user/api +# Required +#MIRAKL_API_KEY= +MIRAKL_API_KEY=fce514ba-c360-4259-8435-8f536701378d + +################################# +###### Onboarding workflow ###### +################################# + +# Enable the seller onboarding workflow. +# Defaults to true. +ENABLE_SELLER_ONBOARDING=true + +# The URL we will redirect the seller to after a successful account creation. +# Will be requested by a seller, must be publicly available. +# Default will be $MIRAKL_HOST_NAME/mmp/shop/account/shop +REDIRECT_ONBOARDING=https://stripe-dev.mirakl.net/mmp/shop/account/shop + +# Your Stripe Webhook Secret. Used to validate received webhooks. +# You can find it when you configure the connect webhook in the dashboard. +# https://dashboard.stripe.com/webhooks, then select the webhook +# Required +#STRIPE_SELLERS_WEBHOOK_SECRET=whsec_xxxxx +STRIPE_SELLERS_WEBHOOK_SECRET=whsec_6ea4b37890ea25fe6bbca9e2e5743c8503327fdde8e87f9d9336c8338932e808 + +# Code of a custom field of type Link which will receive Stripe Express URLs. +# Must be read-only for the seller, and you should leave it blank when creating the account. +# Defaults to stripe-url. +#MIRAKL_CUSTOM_FIELD_CODE=stripe-url + +# Should we prefill the Stripe Express account with seller info read from Mirakl. +# Defaults to false. +STRIPE_PREFILL_ONBOARDING=true + +############################### +###### Payments workflow ###### +############################### + +# Metadata key used in PaymentIntents or Charges to convey the Mirakl commercial order ID. +# Defaults to mirakl_commercial_order_id. +#PAYMENT_METADATA_COMMERCIAL_ORDER_ID=mirakl_commercial_order_id + +# Enable the payment split workflow for product orders. +# Defaults to false. +ENABLE_PRODUCT_PAYMENT_SPLIT=false + +# Enable the payment refund workflow for product orders. +# Defaults to false. +#ENABLE_PRODUCT_PAYMENT_REFUND=false + +# Enable the payment split workflow for service orders. +# Defaults to false. +#ENABLE_SERVICE_PAYMENT_SPLIT=false + +ENABLE_SERVICE_PAYMENT_SPLIT=true + +# Enable the payment refund workflow for service orders. +# Defaults to false. +#ENABLE_SERVICE_PAYMENT_REFUND=false + +ENABLE_SERVICE_PAYMENT_REFUND=true + +# Your Stripe Account Webhook Secret. Used to validate received webhooks. +# You can find it when you configure the connect webhook in the dashboard. +# https://dashboard.stripe.com/webhooks, then select the webhook +# Required +STRIPE_OPERATOR_WEBHOOK_SECRET=whsec_6ea4b37890ea25fe6bbca9e2e5743c8503327fdde8e87f9d9336c8338932e808 + +######################################## +###### Notifications and alerting ###### +######################################## + +# The entire Symfony Mailer configuration using a DSN-like URL format. +# See https://symfony.com/doc/current/components/mailer.html#mailer-dsn +# Example: smtp://user:pass@host:port/?timeout=60&encryption=ssl&auth_mode=login +# Defaults to smtp://null (mailer disabled) +# Required +MAILER_DSN=smtp://null + +# The email which will receive all technical alerts +# Default is empty, required if mailer is configured +#TECHNICAL_ALERT_EMAIL=myemail@example.com + +# The email from which will be send all tehnical mails +# Default is empty, required if mailer is configured +#TECHNICAL_ALERT_EMAIL_FROM=noreply@example.com + +# An URL we will call every time we need to notify you. +# Default is empty: notifications will be disabled +#OPERATOR_NOTIFICATION_URL= + +# A boolean enabling mails when the operator notification URL is not available or the response code is an error. +# Default: true. +#MAIL_ON_NOTIFICATION_ENDPOINT_DOWN=true + +# A duration in minutes. As the notification endpoint down emails can create quite a lot of spam, +# we will wait at least that duration between two notification emails. Default to 10 minutes. +# 0 to disable throttling, can go as high as the notification worker max life, i.e. 3600 by default. +#MAIL_ON_NOTIFICATION_ENDPOINT_DOWN_COOLDOWN=10 + +# Enable the tax split from order total +# Tax amount will be credited to merchants stripe connected account dedicated for taxes +# Update & uncomment below two lines (STRIPE_TAX_ACCOUNT and TAX_ORDER_POSTFIX) & make sure value of TAX_ORDER_POSTFIX must not +# be blank in case if this line is uncommented +#STRIPE_TAX_ACCOUNT=acct_xxxxxxxxxxxxxxx +#TAX_ORDER_POSTFIX=_XXX + +ENABLE_PAYMENT_TAX_SPLIT=true +STRIPE_TAX_ACCOUNT=acct_1MI0I2IPuv9fUgmoXX +#TAX_ORDER_POSTFIX=_TAXX diff --git a/tests/Service/PaymentRefundServiceTest.php b/tests/Service/PaymentRefundServiceTest.php index 651a4e7d..667f4f92 100644 --- a/tests/Service/PaymentRefundServiceTest.php +++ b/tests/Service/PaymentRefundServiceTest.php @@ -163,8 +163,8 @@ public function testGetRetriableProductTransfers() $this->mockRefundCreated($this->getBasicProductRefundFromRepository()); $transfers = $this->paymentRefundService->getTransfersFromOrderRefunds($orders); - $this->assertCount(28, $transfers); - $this->assertCount(28, $this->getProductTransfersFromRepository()); + $this->assertCount(14, $transfers); + $this->assertCount(14, $this->getProductTransfersFromRepository()); // All except ORDER_REFUND_BASIC are retriable $this->assertCount(13, $this->paymentRefundService->getRetriableTransfers()); From 2c6eb90d5bfa01997bc1a7b27aa277b2b9d36faf Mon Sep 17 00:00:00 2001 From: Tejpal Singh Date: Fri, 3 Feb 2023 10:24:50 +0530 Subject: [PATCH 34/40] delete real.env --- real.env | 173 ------------------------------------------------------- 1 file changed, 173 deletions(-) delete mode 100644 real.env diff --git a/real.env b/real.env deleted file mode 100644 index 3ca20e26..00000000 --- a/real.env +++ /dev/null @@ -1,173 +0,0 @@ -########################### -###### Core Settings ###### -########################### - -# Should remain "prod" even when using your sandbox environment. -APP_ENV=prod - -# See https://symfony.com/doc/current/reference/configuration/framework.html#secret -# Required -#APP_SECRET=TO_BE_GENERATED -APP_SECRET=529190034a788e18fd95d6a8e30da739abfaea34 - -# Secret used to authenticate private calls. -# Will have to be in the X-AUTH-TOKEN header of every private request. Please generate a strong secret -#OPERATOR_PASSWORD=TO_BE_GENERATED -OPERATOR_PASSWORD=CMirakl@2022 - -# The scheme on which the connector will be publicly available. -# Used when generating refresh URLs for the onboarding flow. -# Defaults to https -#SCHEME=https - -# The base host on which the connector will be publicly available. -# Used when generating refresh URLs for the onboarding flow. -# Required -#BASE_HOST=stripe-mirakl.example.com -#BASE_HOST=cnetricin-dev.mirakl.net -BASE_HOST=stripe-dev.mirakl.net - -# If you use a proxy, tell Symfony which reverse proxy IP addresses to trust. -# See How to Configure Symfony to Work behind a Load Balancer or a Reverse Proxy: -# https://symfony.com/doc/4.4/deployment/proxies.html -#TRUSTED_PROXIES=127.0.0.1,REMOTE_ADDR - -# The connection URL to your database. -# See https://www.doctrine-project.org/projects/doctrine-dbal/en/2.9/reference/configuration.html#connecting-using-a-url -# Required -#DATABASE_URL=pgsql://symfony:symfony@db:5432/symfony?charset=UTF-8 -DATABASE_URL=pgsql://postgres:77453656@localhost:5432/smc_db_service?charset=UTF-8 - -# The transport used for the queuing system. -# See Symfony Messenger documentation for supported transports: -# https://symfony.com/doc/current/messenger.html#transports-async-queued-messages -# Example for RabbitMQ: amqp://guest:guest@localhost:5672/%2f/messages -# Default is doctrine://default -# Required -MESSENGER_TRANSPORT_DSN=doctrine://default - -# Your Stripe Client Secret. Available in your dashboard. -# https://dashboard.stripe.com/apikeys -# Required -#STRIPE_CLIENT_SECRET=sk_xxxx -STRIPE_CLIENT_SECRET=sk_test_51MHo4lIldRBoiz9oXERfpQhS6UipUYkx6GjRgskSvEuakxFyMScQdva9mb8XqoIuhaaPfre4wKxifa7XebxX6X7B00fKDfmYfO - - - -# Host name of your Mirakl Instance. Will be used as base for all Mirakl API calls. -# Required -#MIRAKL_HOST_NAME=https://mymarketplace.mirakl.net -MIRAKL_HOST_NAME=https://stripe-dev.mirakl.net - -# The Mirakl Operator key. Can be generated as a Mirakl operator -# Recommendation: create a specific operator for the connector. -# Generate the key on https://mymarketplace.mirakl.net/mmp/operator/user/api -# Required -#MIRAKL_API_KEY= -MIRAKL_API_KEY=fce514ba-c360-4259-8435-8f536701378d - -################################# -###### Onboarding workflow ###### -################################# - -# Enable the seller onboarding workflow. -# Defaults to true. -ENABLE_SELLER_ONBOARDING=true - -# The URL we will redirect the seller to after a successful account creation. -# Will be requested by a seller, must be publicly available. -# Default will be $MIRAKL_HOST_NAME/mmp/shop/account/shop -REDIRECT_ONBOARDING=https://stripe-dev.mirakl.net/mmp/shop/account/shop - -# Your Stripe Webhook Secret. Used to validate received webhooks. -# You can find it when you configure the connect webhook in the dashboard. -# https://dashboard.stripe.com/webhooks, then select the webhook -# Required -#STRIPE_SELLERS_WEBHOOK_SECRET=whsec_xxxxx -STRIPE_SELLERS_WEBHOOK_SECRET=whsec_6ea4b37890ea25fe6bbca9e2e5743c8503327fdde8e87f9d9336c8338932e808 - -# Code of a custom field of type Link which will receive Stripe Express URLs. -# Must be read-only for the seller, and you should leave it blank when creating the account. -# Defaults to stripe-url. -#MIRAKL_CUSTOM_FIELD_CODE=stripe-url - -# Should we prefill the Stripe Express account with seller info read from Mirakl. -# Defaults to false. -STRIPE_PREFILL_ONBOARDING=true - -############################### -###### Payments workflow ###### -############################### - -# Metadata key used in PaymentIntents or Charges to convey the Mirakl commercial order ID. -# Defaults to mirakl_commercial_order_id. -#PAYMENT_METADATA_COMMERCIAL_ORDER_ID=mirakl_commercial_order_id - -# Enable the payment split workflow for product orders. -# Defaults to false. -ENABLE_PRODUCT_PAYMENT_SPLIT=false - -# Enable the payment refund workflow for product orders. -# Defaults to false. -#ENABLE_PRODUCT_PAYMENT_REFUND=false - -# Enable the payment split workflow for service orders. -# Defaults to false. -#ENABLE_SERVICE_PAYMENT_SPLIT=false - -ENABLE_SERVICE_PAYMENT_SPLIT=true - -# Enable the payment refund workflow for service orders. -# Defaults to false. -#ENABLE_SERVICE_PAYMENT_REFUND=false - -ENABLE_SERVICE_PAYMENT_REFUND=true - -# Your Stripe Account Webhook Secret. Used to validate received webhooks. -# You can find it when you configure the connect webhook in the dashboard. -# https://dashboard.stripe.com/webhooks, then select the webhook -# Required -STRIPE_OPERATOR_WEBHOOK_SECRET=whsec_6ea4b37890ea25fe6bbca9e2e5743c8503327fdde8e87f9d9336c8338932e808 - -######################################## -###### Notifications and alerting ###### -######################################## - -# The entire Symfony Mailer configuration using a DSN-like URL format. -# See https://symfony.com/doc/current/components/mailer.html#mailer-dsn -# Example: smtp://user:pass@host:port/?timeout=60&encryption=ssl&auth_mode=login -# Defaults to smtp://null (mailer disabled) -# Required -MAILER_DSN=smtp://null - -# The email which will receive all technical alerts -# Default is empty, required if mailer is configured -#TECHNICAL_ALERT_EMAIL=myemail@example.com - -# The email from which will be send all tehnical mails -# Default is empty, required if mailer is configured -#TECHNICAL_ALERT_EMAIL_FROM=noreply@example.com - -# An URL we will call every time we need to notify you. -# Default is empty: notifications will be disabled -#OPERATOR_NOTIFICATION_URL= - -# A boolean enabling mails when the operator notification URL is not available or the response code is an error. -# Default: true. -#MAIL_ON_NOTIFICATION_ENDPOINT_DOWN=true - -# A duration in minutes. As the notification endpoint down emails can create quite a lot of spam, -# we will wait at least that duration between two notification emails. Default to 10 minutes. -# 0 to disable throttling, can go as high as the notification worker max life, i.e. 3600 by default. -#MAIL_ON_NOTIFICATION_ENDPOINT_DOWN_COOLDOWN=10 - -# Enable the tax split from order total -# Tax amount will be credited to merchants stripe connected account dedicated for taxes -# Update & uncomment below two lines (STRIPE_TAX_ACCOUNT and TAX_ORDER_POSTFIX) & make sure value of TAX_ORDER_POSTFIX must not -# be blank in case if this line is uncommented -#STRIPE_TAX_ACCOUNT=acct_xxxxxxxxxxxxxxx -#TAX_ORDER_POSTFIX=_XXX - -ENABLE_PAYMENT_TAX_SPLIT=true -STRIPE_TAX_ACCOUNT=acct_1MI0I2IPuv9fUgmoXX -#TAX_ORDER_POSTFIX=_TAXX From a815766c068caae71372557edc2d574b8c4f546b Mon Sep 17 00:00:00 2001 From: Tejpal Singh Date: Tue, 7 Feb 2023 01:50:03 -0800 Subject: [PATCH 35/40] ran php cs-fixer --- src/Service/PaymentSplitService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Service/PaymentSplitService.php b/src/Service/PaymentSplitService.php index 83f78ed2..2e5d2dc4 100644 --- a/src/Service/PaymentSplitService.php +++ b/src/Service/PaymentSplitService.php @@ -26,7 +26,7 @@ public function __construct( StripeTransferRepository $stripeTransferRepository, MiraklClient $miraklClient, bool $enablePaymentTaxSplit, - string $taxOrderPostfix, + string $taxOrderPostfix ) { $this->stripeTransferFactory = $stripeTransferFactory; $this->stripeTransferRepository = $stripeTransferRepository; From b88dc7cac2dc409ee90d405bc3e9bf7ebe86c523 Mon Sep 17 00:00:00 2001 From: Tejpal Singh Date: Tue, 7 Feb 2023 01:56:04 -0800 Subject: [PATCH 36/40] ran phpstan --- src/Service/PaymentRefundService.php | 2 ++ src/Service/PaymentSplitService.php | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Service/PaymentRefundService.php b/src/Service/PaymentRefundService.php index a5d59767..49d6194b 100644 --- a/src/Service/PaymentRefundService.php +++ b/src/Service/PaymentRefundService.php @@ -30,6 +30,8 @@ class PaymentRefundService */ private $stripeTransferRepository; + private $taxOrderPostfix; + public function __construct( StripeRefundFactory $stripeRefundFactory, StripeTransferFactory $stripeTransferFactory, diff --git a/src/Service/PaymentSplitService.php b/src/Service/PaymentSplitService.php index 2e5d2dc4..2134840c 100644 --- a/src/Service/PaymentSplitService.php +++ b/src/Service/PaymentSplitService.php @@ -2,7 +2,7 @@ namespace App\Service; -use App\Service\MiraklClient; +//use App\Service\MiraklClient; use App\Factory\StripeTransferFactory; use App\Repository\StripeTransferRepository; @@ -24,7 +24,7 @@ class PaymentSplitService public function __construct( StripeTransferFactory $stripeTransferFactory, StripeTransferRepository $stripeTransferRepository, - MiraklClient $miraklClient, + //MiraklClient $miraklClient, bool $enablePaymentTaxSplit, string $taxOrderPostfix ) { From be208867e3af1e217e339cfb7dc15a51330eb059 Mon Sep 17 00:00:00 2001 From: Tejpal Singh Date: Tue, 7 Feb 2023 02:11:54 -0800 Subject: [PATCH 37/40] ran phpunit and fixed E --- src/Service/PaymentSplitService.php | 2 -- tests/Service/PaymentSplitServiceTest.php | 1 - 2 files changed, 3 deletions(-) diff --git a/src/Service/PaymentSplitService.php b/src/Service/PaymentSplitService.php index 2134840c..5ca29a39 100644 --- a/src/Service/PaymentSplitService.php +++ b/src/Service/PaymentSplitService.php @@ -2,7 +2,6 @@ namespace App\Service; -//use App\Service\MiraklClient; use App\Factory\StripeTransferFactory; use App\Repository\StripeTransferRepository; @@ -24,7 +23,6 @@ class PaymentSplitService public function __construct( StripeTransferFactory $stripeTransferFactory, StripeTransferRepository $stripeTransferRepository, - //MiraklClient $miraklClient, bool $enablePaymentTaxSplit, string $taxOrderPostfix ) { diff --git a/tests/Service/PaymentSplitServiceTest.php b/tests/Service/PaymentSplitServiceTest.php index e0772322..77fcf14f 100644 --- a/tests/Service/PaymentSplitServiceTest.php +++ b/tests/Service/PaymentSplitServiceTest.php @@ -60,7 +60,6 @@ protected function setUp(): void $this->paymentSplitService = new PaymentSplitService( $stripeTransferFactory, $this->stripeTransferRepository, - $this->miraklClient, false, '_TAX' ); From e7e2853a29a084b617a2c5528db300fdfd7799c5 Mon Sep 17 00:00:00 2001 From: Tejpal Singh Date: Wed, 8 Feb 2023 08:43:29 +0530 Subject: [PATCH 38/40] unit test updated --- tests/Factory/StripePayoutFactoryTest.php | 4 ++-- tests/Factory/StripeTransferFactoryTest.php | 16 +++++++-------- tests/MiraklMockedHttpClient.php | 2 +- tests/Service/PaymentRefundServiceTest.php | 20 +++++++++---------- tests/Service/SellerSettlementServiceTest.php | 2 +- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/tests/Factory/StripePayoutFactoryTest.php b/tests/Factory/StripePayoutFactoryTest.php index 747db7e9..abeb0771 100644 --- a/tests/Factory/StripePayoutFactoryTest.php +++ b/tests/Factory/StripePayoutFactoryTest.php @@ -74,7 +74,7 @@ public function testUpdateFromInvoice() MiraklMockedHttpClient::INVOICE_DATE_1_VALID )); $invoice['invoice_id'] = $invoiceId; - $payout = $this->stripePayoutFactory->updateFromInvoice($payout, $invoice); + $payout = $this->stripePayoutFactory->updateFromInvoice($payout, $invoice, $this->miraklClient); $this->assertEquals(StripePayout::PAYOUT_PENDING, $payout->getStatus()); } @@ -112,7 +112,7 @@ public function testInvoiceWithPayout() $this->assertEquals(StripePayout::PAYOUT_PENDING, $payout->getStatus()); $payout->setPayoutId(StripeMockedHttpClient::PAYOUT_BASIC); - $payout = $this->stripePayoutFactory->updateFromInvoice($payout, $invoice); + $payout = $this->stripePayoutFactory->updateFromInvoice($payout, $invoice, $this->miraklClient); $this->assertEquals(StripePayout::PAYOUT_CREATED, $payout->getStatus()); } } diff --git a/tests/Factory/StripeTransferFactoryTest.php b/tests/Factory/StripeTransferFactoryTest.php index b5bdd997..cbad8611 100644 --- a/tests/Factory/StripeTransferFactoryTest.php +++ b/tests/Factory/StripeTransferFactoryTest.php @@ -162,7 +162,7 @@ public function testCreateFromProductOrder() $this->assertNotNull($transfer->getAccountMapping()); $this->assertNull($transfer->getTransferId()); $this->assertNull($transfer->getTransactionId()); - $this->assertEquals(8073, $transfer->getAmount()); + $this->assertEquals(7205, $transfer->getAmount()); $this->assertEquals('eur', $transfer->getCurrency()); $this->assertNotNull($transfer->getMiraklCreatedDate()); } @@ -296,12 +296,12 @@ public function testProductOrderInvalidAmount() public function testProductOrderDifferentAmounts() { $amounts = [ - 'NO_COMMISSION' => 8472, + 'NO_COMMISSION' => 7604, 'NO_TAX' => 6513, - 'TAX_INCLUDED' => 6513, - 'PARTIAL_TAX' => 7293, + 'TAX_INCLUDED' => 5645, + 'PARTIAL_TAX' => 6959, 'NO_SALES_TAX' => 7205, - 'NO_SHIPPING_TAX' => 7381 + 'NO_SHIPPING_TAX' => 6513 ]; foreach ($amounts as $const => $expectedAmount) { @@ -403,7 +403,7 @@ public function testCreateFromServiceOrder() $this->assertNotNull($transfer->getAccountMapping()); $this->assertNull($transfer->getTransferId()); $this->assertNull($transfer->getTransactionId()); - $this->assertEquals(1415, $transfer->getAmount()); + $this->assertEquals(1081, $transfer->getAmount()); $this->assertEquals('eur', $transfer->getCurrency()); $this->assertNotNull($transfer->getMiraklCreatedDate()); } @@ -521,10 +521,10 @@ public function testServiceOrderInvalidAmount() public function testServiceOrderDifferentAmounts() { $amounts = [ - 'NO_COMMISSION' => 1814, + 'NO_COMMISSION' => 1480, 'NO_TAX' => 1081, 'TAX_INCLUDED' => 1081, - 'PARTIAL_TAX' => 1237, + 'PARTIAL_TAX' => 1081, ]; foreach ($amounts as $const => $expectedAmount) { diff --git a/tests/MiraklMockedHttpClient.php b/tests/MiraklMockedHttpClient.php index 761c408b..1ee7ce2c 100644 --- a/tests/MiraklMockedHttpClient.php +++ b/tests/MiraklMockedHttpClient.php @@ -1147,7 +1147,7 @@ private function mockTransactionsLogsByDocumentNumber() [ 'id' => rand(1, 1000), 'type' => 'ORDER_AMOUNT_TAX', - 'amount' => 100, + 'amount' => 0, ], ]; } diff --git a/tests/Service/PaymentRefundServiceTest.php b/tests/Service/PaymentRefundServiceTest.php index 667f4f92..8c8dbc9d 100644 --- a/tests/Service/PaymentRefundServiceTest.php +++ b/tests/Service/PaymentRefundServiceTest.php @@ -163,11 +163,11 @@ public function testGetRetriableProductTransfers() $this->mockRefundCreated($this->getBasicProductRefundFromRepository()); $transfers = $this->paymentRefundService->getTransfersFromOrderRefunds($orders); - $this->assertCount(14, $transfers); + $this->assertCount(28, $transfers); $this->assertCount(14, $this->getProductTransfersFromRepository()); // All except ORDER_REFUND_BASIC are retriable - $this->assertCount(13, $this->paymentRefundService->getRetriableTransfers()); + $this->assertCount(27, $this->paymentRefundService->getRetriableTransfers()); $this->assertCount(14, $this->getProductTransfersFromRepository()); } @@ -180,12 +180,12 @@ public function testGetTransfersFromProductOrders() $this->mockRefundCreated($this->getBasicProductRefundFromRepository()); $transfers = $this->paymentRefundService->getTransfersFromOrderRefunds($orders); - $this->assertCount(14, $transfers); + $this->assertCount(28, $transfers); $this->assertCount(14, $this->getProductTransfersFromRepository()); // All except ORDER_REFUND_BASIC are retriable $transfers = $this->paymentRefundService->getRetriableTransfers(); - $this->assertCount(13, $transfers); + $this->assertCount(27, $transfers); $this->assertCount(14, $this->getProductTransfersFromRepository()); } @@ -212,7 +212,7 @@ public function testUpdateProductTransfers() $this->assertCount(14, $refunds); $transfers = $this->paymentRefundService->getTransfersFromOrderRefunds($orders); - $this->assertCount(14, $transfers); + $this->assertCount(28, $transfers); $this->assertCount(14, $this->getProductTransfersFromRepository()); // ORDER_REFUND_BASIC is on hold @@ -236,11 +236,11 @@ public function testGetRetriableServiceTransfers() $this->mockRefundCreated($this->getBasicServiceRefundFromRepository()); $transfers = $this->paymentRefundService->getTransfersFromOrderRefunds($orders); - $this->assertCount(14, $transfers); + $this->assertCount(28, $transfers); $this->assertCount(14, $this->getServiceTransfersFromRepository()); // All except ORDER_REFUND_BASIC are retriable - $this->assertCount(13, $this->paymentRefundService->getRetriableTransfers()); + $this->assertCount(27, $this->paymentRefundService->getRetriableTransfers()); $this->assertCount(14, $this->getServiceTransfersFromRepository()); } @@ -253,12 +253,12 @@ public function testGetTransfersFromServiceOrders() $this->mockRefundCreated($this->getBasicServiceRefundFromRepository()); $transfers = $this->paymentRefundService->getTransfersFromOrderRefunds($orders); - $this->assertCount(14, $transfers); + $this->assertCount(28, $transfers); $this->assertCount(14, $this->getServiceTransfersFromRepository()); // All except ORDER_REFUND_BASIC are retriable $transfers = $this->paymentRefundService->getRetriableTransfers(); - $this->assertCount(13, $transfers); + $this->assertCount(27, $transfers); $this->assertCount(14, $this->getServiceTransfersFromRepository()); } @@ -285,7 +285,7 @@ public function testUpdateServiceTransfers() $this->assertCount(14, $refunds); $transfers = $this->paymentRefundService->getTransfersFromOrderRefunds($orders); - $this->assertCount(14, $transfers); + $this->assertCount(28, $transfers); $this->assertCount(14, $this->getServiceTransfersFromRepository()); // ORDER_REFUND_BASIC is on hold diff --git a/tests/Service/SellerSettlementServiceTest.php b/tests/Service/SellerSettlementServiceTest.php index 6df83eef..5c587607 100644 --- a/tests/Service/SellerSettlementServiceTest.php +++ b/tests/Service/SellerSettlementServiceTest.php @@ -194,7 +194,7 @@ public function testUpdatePayoutsFromInvoices() $id = MiraklMockedHttpClient::INVOICE_INVALID_SHOP; $invoices[$id]['shop_id'] = MiraklMockedHttpClient::SHOP_BASIC; $payouts = $this->sellerSettlementService - ->updatePayoutsFromInvoices($payouts, $invoices); + ->updatePayoutsFromInvoices($payouts, $invoices, $this->miraklClient); $this->assertCount(1, $payouts); $payouts = $this->getPayoutsFromRepository(); From f0f7ce24fe4c49dc26af27b170233ae4725c0eed Mon Sep 17 00:00:00 2001 From: Tejpal Singh Date: Wed, 8 Feb 2023 18:18:58 +0530 Subject: [PATCH 39/40] gitignore --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index f9334c0b..5ab485b2 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,7 @@ vendor bin/.phpunit/ .env .idea/* +.settings +.buildpath +.project +clover.xml From efc594398ac66e7ff15a8483363c1b19351c6c23 Mon Sep 17 00:00:00 2001 From: Tejpal Singh Date: Tue, 14 Feb 2023 16:33:19 +0530 Subject: [PATCH 40/40] env dist updated --- .env.dist | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.env.dist b/.env.dist index 55f6f5fb..3adb5316 100644 --- a/.env.dist +++ b/.env.dist @@ -146,9 +146,6 @@ MAILER_DSN=smtp://null # 0 to disable throttling, can go as high as the notification worker max life, i.e. 3600 by default. #MAIL_ON_NOTIFICATION_ENDPOINT_DOWN_COOLDOWN=10 -# Enable the tax split from order total -# Tax amount will be credited to merchants stripe connected account dedicated for taxes -# Update & uncomment below two lines (STRIPE_TAX_ACCOUNT and TAX_ORDER_POSTFIX) & make sure value of TAX_ORDER_POSTFIX must not -# be blank in case if this line is uncommented -#STRIPE_TAX_ACCOUNT=acct_xxxxxxxxxxxxxxx -#TAX_ORDER_POSTFIX=_XXX \ No newline at end of file +# Tax split configuration for new product order & backlog product order, for new service order & backlog service order +#ENABLE_PAYMENT_TAX_SPLIT=false +#STRIPE_TAX_ACCOUNT=acct_xxxxxx \ No newline at end of file