@@ -60,10 +60,11 @@ public function paid(Product $product): ?Transfer
6060
6161 /**
6262 * @param Product $product
63+ * @param bool $force
6364 * @return bool
6465 * @throws
6566 */
66- public function refund (Product $ product ): bool
67+ public function refund (Product $ product, bool $ force = false ): bool
6768 {
6869 $ transfer = $ this ->paid ($ product );
6970
@@ -72,23 +73,38 @@ public function refund(Product $product): bool
7273 ->setModel ($ this ->transfers ()->getMorphClass ());
7374 }
7475
75- return DB ::transaction (function () use ($ product , $ transfer ) {
76- $ product ->transfer ($ this , $ product ->getAmountProduct (), $ product ->getMetaProduct ());
76+ return DB ::transaction (function () use ($ product , $ transfer , $ force ) {
77+ if ($ force ) {
78+ $ product ->forceTransfer ($ this , $ product ->getAmountProduct (), $ product ->getMetaProduct ());
79+ } else {
80+ $ product ->transfer ($ this , $ product ->getAmountProduct (), $ product ->getMetaProduct ());
81+ }
82+
7783 return $ transfer ->update (['refund ' => 1 ]);
7884 });
7985 }
8086
8187 /**
8288 * @param Product $product
89+ * @param bool $force
8390 * @return bool
8491 */
85- public function safeRefund (Product $ product ): bool
92+ public function safeRefund (Product $ product, bool $ force = false ): bool
8693 {
8794 try {
88- return $ this ->refund ($ product );
95+ return $ this ->refund ($ product, $ force );
8996 } catch (\Throwable $ throwable ) {
9097 return false ;
9198 }
9299 }
93100
101+ /**
102+ * @param Product $product
103+ * @return bool
104+ */
105+ public function forceRefund (Product $ product ): bool
106+ {
107+ return $ this ->refund ($ product , true );
108+ }
109+
94110}
0 commit comments