From 31afd09a0f95acbe8ed517f81c79cf1c9dd3759e Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 6 Sep 2019 15:22:05 +1000 Subject: [PATCH] Working on stripe payments using Omnipay --- app/PaymentDrivers/BasePaymentDriver.php | 41 ++++++++++++++++++++-- app/PaymentDrivers/StripePaymentDriver.php | 11 +++++- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/app/PaymentDrivers/BasePaymentDriver.php b/app/PaymentDrivers/BasePaymentDriver.php index c9beee5abc52..b50f1e2ffad8 100644 --- a/app/PaymentDrivers/BasePaymentDriver.php +++ b/app/PaymentDrivers/BasePaymentDriver.php @@ -38,7 +38,8 @@ class BasePaymentDriver //$this->gatewayType = $gatewayType ?: $this->gatewayTypes()[0]; } - /* Stubbed in parent, but should never be initialized + /* Stubbed in parent. + * * The boot method should be used in the superclass * to initialize all the member variables for the * given driver / payment gateway @@ -46,8 +47,7 @@ class BasePaymentDriver * ie. * * ->gateway() - * ->setRefundable(true) - * ->setTokenBilling(true) + * ->boot() * * @return Instance */ @@ -108,4 +108,39 @@ class BasePaymentDriver { } + + /************************************* Omnipay ****************************************** + authorize($options) - authorize an amount on the customer's card + completeAuthorize($options) - handle return from off-site gateways after authorization + capture($options) - capture an amount you have previously authorized + purchase($options) - authorize and immediately capture an amount on the customer's card + completePurchase($options) - handle return from off-site gateways after purchase + refund($options) - refund an already processed transaction + void($options) - generally can only be called up to 24 hours after submitting a transaction + acceptNotification() - convert an incoming request from an off-site gateway to a generic notification object for further processing + */ + + public function purchase($data, $items) + { + $response = $this->gateway + ->purchase($data) + ->setItems($items) + ->send(); + + + if ($response->isRedirect()) { + // redirect to offsite payment gateway + $response->redirect(); + } elseif ($response->isSuccessful()) { + // payment was successful: update database + print_r($response); + } else { + // payment failed: display message to customer + echo $response->getMessage(); + + + /* + $this->purchaseResponse = (array)$response->getData();*/ + } + } \ No newline at end of file diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index 5028998cb5fe..4d8d913a0d94 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -15,7 +15,17 @@ use Stripe\Stripe; class StripePaymentDriver extends BasePaymentDriver { + protected $refundable = true; + protected $token_billing = true; + + protected $customer_reference = 'customerReferenceParam'; + + public function boot() + { + $this->setRefundable($this->refundable); + $this->setTokenBilling($this->token_billing); + } /** * Methods in this class are divided into * two separate streams @@ -38,7 +48,6 @@ class StripePaymentDriver extends BasePaymentDriver - /************************************** Stripe API methods **********************************************************/ public function init($api_key)