the browser-facing portion of osu!
at master 47 lines 1.2 kB view raw
1<?php 2 3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0. 4// See the LICENCE file in the repository root for full licence text. 5 6namespace App\Models\Store; 7 8/** 9 * Records transaction data from payment providers. 10 * 11 * @property bool $cancelled 12 * @property string|null $country_code 13 * @property \Carbon\Carbon|null $created_at 14 * @property int $id 15 * @property Order $order 16 * @property int $order_id 17 * @property ?\Carbon\Carbon $paid_at 18 * @property ?string $provider 19 * @property ?string $transaction_id 20 * @property \Carbon\Carbon|null $updated_at 21 */ 22class Payment extends Model 23{ 24 protected $casts = [ 25 'cancelled' => 'boolean', 26 'paid_at' => 'datetime', 27 ]; 28 29 public function order() 30 { 31 return $this->belongsTo(Order::class, 'order_id'); 32 } 33 34 public function getOrderTransactionId() 35 { 36 return "{$this->provider}-{$this->transaction_id}"; 37 } 38 39 public function cancel() 40 { 41 $payment = $this->replicate(); 42 $payment->cancelled = true; 43 $payment->saveOrExplode(); 44 45 datadog_increment('store.payments.cancelled', ['provider' => $this->provider]); 46 } 47}