Skip to content

Instantly share code, notes, and snippets.

@totten

totten/ex.php Secret

Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save totten/831da81e5d02918bcb9f to your computer and use it in GitHub Desktop.
Save totten/831da81e5d02918bcb9f to your computer and use it in GitHub Desktop.
Making a broad but concrete+simple interface to event registration + contributions + memberships. A few simplifications (which seem acceptable): there's no need to create arbitrary line items; line-items are only created in the context of a participant/membership/contribution. At most, you might tweak the line-item that's autogenerated.
<?php
interface CiviInvoice {
/**
* Add details about a registration which a constituent would like to purchase.
*
* @param Participant $participant
* The event-registration which would be purchased.
* @return LineItem
* A new line item which represents the would-be registration.
*/
function addParticipant($participant);
/**
* @param Contribution $contribution
* @return LineItem
*/
function addContribution($contribution);
/**
* @param Membership $membership
* @return LineItem
*/
function addMembership($membership);
/**
* @param Payment $payment
*/
function addPayment($payment);
/**
* @return array<LineItem>
*/
function getLineItems();
/**
* @return LineItem
*/
function getLineItem(int $lineItemID);
/**
* @return Participant|Membership|Contribution
*/
function getLineItemTarget($int $lineItemID);
function getPayments();
function removeLineItem(int $lineItemID)
}
// Usage
$ci = new CiviInvoice();
$ci->addMembership(...membership1...);
$ci->addMembership(...membershp2...);
$ci->addContribution(...);
$entityManager->persist($ci);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment