Skip to content

Instantly share code, notes, and snippets.

@adri
Created September 26, 2018 14:28
Show Gist options
  • Save adri/c358bafe29d87d9ebdb12e6133828d55 to your computer and use it in GitHub Desktop.
Save adri/c358bafe29d87d9ebdb12e6133828d55 to your computer and use it in GitHub Desktop.
Example PaymentContext for creating a payment object.
<?php
class PaymentContext
{
/**
* @var PaymentId
*/
public $paymentId;
/**
* @var Money
*/
public $amount;
public function create(Factory $factory) : Payment
{
return new Payment(
$this->paymentId ?? PaymentId::create(), // random id
$this->amount ?? new Money(\random_int(10, 9999), new Currency('EUR'));
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment