/** * Register a received amount against a purchase. * * @param \Hamjoint\Mustard\Commerce\Purchase $purchase * @param float $amount * @return void */ public static function paymentReceived(Purchase $purchase, $amount) { $purchase->received += $amount; if ($purchase->received >= $purchase->grandTotal) { $purchase->paid = time(); $purchase->item->seller->sendEmail('You have received a payment', 'emails.item.paid', ['total' => $purchase->received, 'item_name' => $purchase->item->name, 'buyer_name' => $purchase->name, 'buyer_street1' => $purchase->street1, 'buyer_street2' => $purchase->street2, 'buyer_city' => $purchase->city, 'buyer_county' => $purchase->county, 'buyer_postcode' => $purchase->postcode, 'buyer_country' => Iso3166::get($purchase->country)->name, 'has_delivery' => $purchase->hasDelivery(), 'has_address' => $purchase->hasAddress(), 'purchase_id' => $purchase->purchaseId, 'full' => $purchase->received == 0]); $purchase->buyer->sendEmail('Receipt for your item', 'emails.item.receipt', ['total' => $purchase->received, 'item_name' => $purchase->item->name, 'seller_name' => $purchase->name, 'seller_street1' => $purchase->street1, 'seller_street2' => $purchase->street2, 'seller_city' => $purchase->city, 'seller_county' => $purchase->county, 'seller_postcode' => $purchase->postcode, 'seller_country' => Iso3166::get($purchase->country)->name, 'full' => $purchase->received == 0, 'has_delivery' => $purchase->hasDelivery(), 'has_address' => $purchase->hasAddress(), 'is_paid' => $purchase->isPaid()]); } $purchase->save(); }