'boolean'
];
public static function booted() {
static::creating( function ( $model ) {
$model->uuid = Str::uuid();
} );
}
public function restaurant() {
return $this->belongsTo( Restaurant::class );
}
public function booking() {
return $this->belongsTo( Booking::class );
}
// Voucher purchases (addon_gift_cards): a payment row can belong to a voucher
// instead of a booking (booking_id NULL, voucher_id set).
public function voucher() {
return $this->belongsTo( Voucher::class );
}
public function getSettingsAttribute() {
$data = $this->attributes['settings'];
if (is_string($data)) {
$data = json_decode( $this->attributes['settings'], true );
}
if ( ! is_array( $data ) ) {
return [];
}
return $data;
}
public function getReceiptDataFormatted(){
$function = $this->payment_type.'DataFormatted';
return $this->{$function};
}
/*
public function getRedsysDataFormattedAttribute_OLD() {
$skip_keys = [ 'DS_MERCHANT_URLOK', 'DS_MERCHANT_URLKO', 'DS_MERCHANT_MERCHANTURL' ];
$settings = $this->settings;
if ( isset( $settings['redsys']['vars'] ) ) {
$vars = $settings['redsys']['vars'];
$message = "
";
foreach ( $vars as $key => $value ) {
if ( ! in_array( $key, $skip_keys ) ) {
$message .= "
{$key}: {$value}
";
}
}
$message .= "
";
return $message;
}
return null;
}*/
// To try payment from view booking I am using the same intent secret
public function getStripeClientSecretAttribute() {
return $this->get_setting( 'stripe_client_secret' );
}
// Solo stripe tiene receipt link
public function hasReceipt() {
if ($this->payment_type == 'stripe' && $this->status == PaymentStatus::SUCCEEDED) {
return true;
}
return false;
}
public function canChargeAfter() {
return $this->payment_type == 'stripe' && $this->status == PaymentStatus::SUCCEEDED_CAPTURE;
}
public function getCustomerPaymentMethods() {
try {
if ( $this->payment_type == 'stripe' )
{
if ($this->is_sandbox) {
$stripe_customer_id = $this->booking->customer->sandboxStripeId;
} else {
$stripe_customer_id = $this->booking->customer->stripeId;
}
$gateway = new GatewayStripe( $this->restaurant_id );
$list = $gateway->getCustomerPaymentMethods( $stripe_customer_id );
return $list;
}
} catch ( \Exception $e ) {
return [];
}
return [];
}
// Charge customer
public function chargeCustomerWithPaymentMethodId( $payment_method_id ) {
if ( $this->payment_type == 'stripe' )
{
if ($this->is_sandbox) {
$stripe_customer_id = $this->booking->customer->sandboxStripeId;
} else {
$stripe_customer_id = $this->booking->customer->stripeId;
}
$gateway = new GatewayStripe( $this->restaurant_id );
$result = $gateway->chargeCustomer( $this->booking->id, $stripe_customer_id, $this->amount, $this->currency, $payment_method_id );
return $result;
}
return null;
/*try {
if ( $this->payment_type == 'stripe' ) {
$customer_id = $this->booking->customer->stripeId;
$gateway = new GatewayStripe( $this->restaurant_id );
$result = $gateway->chargeCustomer( $this->booking->id, $customer_id, $this->amount, $this->currency, $payment_method_id );
return $result;
}
} catch ( \Exception $e ) {
return null;
}
return null;*/
}
public function chargeCustomerPreauthorized()
{
try {
if ( $this->payment_type == 'stripe' ) {
$customer_id = $this->booking->customer->stripeId;
$gateway = new GatewayStripe( $this->restaurant_id );
$result = $gateway->capturePreauthorizedPayment( $this->stripe_payment_intent_id, $this->booking->id, $customer_id, $this->amount, $this->currency );
return $result;
}
} catch ( \Exception $e ) {
return null;
}
return null;
}
public function toCustomArray() {
return self::toDataArray($this);
}
/**
* Used for mybooking view
* @param $payment
*
* @return array
*/
public static function toDataArray($payment) {
if (!$payment) return [];
return [
'status' => $payment->status,
'id' => $payment->id,
'restaurant_id' => $payment->restaurant_id,
'booking_id' => $payment->booking_id,
'amount' => $payment->amount,
'payment_type' => $payment->payment_type,
'currency' => $payment->currency,
'status' => $payment->status,
'stripe_payment_status' => $payment->stripe_payment_status,
'stripe_payment_intent_id' => $payment->stripe_payment_intent_id
];
}
}