Payments
Payments are simply a stream entry/model that are bound to a gateway
extension.
Processing Payments
After installing and configuring your payment gateway extension(s) you can create a payment and process it like this:
$payment = new PaymentModel(
[
'amount' => 25.00,
'currency' => 'USD',
'first_name' => 'Ryan',
'last_name' => 'Thompson',
'number' => '4242424242424242',
'type' => 'visa',
'security_code' => '123',
'expiration_month' => '12',
'expiration_year' => '2020',
'gateway' => 'stripe',
'related' => $order, // Optional related order / product / object
]
);
$payment->purchase(); // Returns bool
The gateway value can be an instance or any valid string identifier.{.tip}
Payment Authorization
To authorize the payment only, use the authorize
method on the payment instance.
$payment->authorize(); // Returns bool
If authorizing only you will need to capture
the payment later to secure the payment funds.
$payment = $payments->findByStrId($id);
$payment->capture(); // Returns bool
Refunding a Payment
To refund a payment simply call the refund
method on an existing payment instance:
$payment = $payments->findByStrId($id);
$payment->refund(); // Returns bool
Payment Statuses
You can determine what state a payment is in by checking it's status:
// Payment processing here
if ($payment->isSuccessful()) {
echo 'Yas!';
} else {
echo $payment->getLastLog()->getMessage();
}
if ($payment->isAuthorized()) {
echo 'Please capture the payment.';
} elseif($payment->isComplete()) {
echo 'Thank you for your payment.';
} elseif($payment->isFailed()) {
echo 'Your payment failed.';
} elseif ($payment->isRefunded()) {
echo 'Thank you for nothing.';
}