IQnection\Payment\Payment
Example of processing payment in form handler // validate the payment submission $inValid = $Payment->ValidateSubmission($data); if (count($inValid)) { foreach($inValid as $fieldName => $message) { $form->addErrorMessage($fieldName,$message,'bad'); } return $this->redirectback(); }
// process the payment
$Payment->Amount = $Booking->FinalPrice();
$Payment->Process($data);
switch($Payment->Status)
{
default:
case 'Pending':
{
user_error('Pending status has not been setup yet');
return $this;
break;
}
case 'Failed':
{
$form->sessionMessage('There was an error processing your payment, "'.$Payment->Message.'". If the problem persists, please contact the site administrator','bad');
return $this->redirectback();
break;
}
case 'Declined':
{
$form->sessionMessage("Your payment was declined, please check with your bank and try again. Message:".$Payment->Message,'bad');
return $this->redirectback();
break;
}
case 'Success':
{
$Booking->PaymentID = $Payment->ID;
$Booking->BookingPageID = $this->ID;
$Booking->Complete();
Session::set('Form_PaymentForm.data',false);
return $this->redirect($this->Link('thanks/'.$Booking->HashedID()));
break;
}
}
Synopsis
- // constants
- const STATUS_PENDING = 'Pending';
- const STATUS_FAILED = 'Failed';
- const STATUS_DECLINED = 'Declined';
- const STATUS_SUCCESS = 'Success';
- // members
- private static string $table_name = 'Payment';
- private static string $PaymentMethod = 'Not Specified';
- private static array $db = ;
- private static array $has_one = ;
- private static array $summary_fields = ;
- private static string $default_sort = 'Created DESC';
- // methods
- public void getCMSFields()
- public void getPaidObject()
- public void setPaidObject()
- public void PaymentFields()
- public void PaymentRequiredFields()
- public void ValidateSubmission()
- public void Process()
- public void PaymentMethodTitle()
- public void OnSuccessfulPayment()
- public void canCreate()
- public void canDelete()
- public void canEdit()
- public void canView()
- public void Method()
Hierarchy
Extends
- SilverStripe\ORM\DataObject
Constants
Name | Value |
---|---|
STATUS_PENDING | 'Pending' |
STATUS_FAILED | 'Failed' |
STATUS_DECLINED | 'Declined' |
STATUS_SUCCESS | 'Success' |
Members
private
- $PaymentMethod
- $db
- $default_sort
- $has_one
- $summary_fields
- $table_name
Methods
public
- Method()
- OnSuccessfulPayment()
- PaymentFields() — Builds the form fields needed for payment fields should be returned in an array to ba parsed and added to the page's form
- PaymentMethodTitle()
- PaymentRequiredFields()
- Process() — the process method should validate the payment and process it with any 3rd party upon success, write the payment object to the database
- ValidateSubmission() — checks the submission and makes sure all values are good before processing the payment this method should be called from the form handler.
- canCreate()
- canDelete()
- canEdit()
- canView()
- getCMSFields()
- getPaidObject()
- setPaidObject()