@@ -143,6 +143,11 @@ public function doDirectPayment(&$params, $component = 'contribute') {
143
143
if (!empty ($ params ['is_recur ' ])) {
144
144
$ response = $ this ->gateway ->createCard ($ this ->getCreditCardOptions (array_merge ($ params , array ('action ' => 'Purchase ' )), $ component ))->send ();
145
145
}
146
+ elseif (!empty ($ params ['token ' ])) {
147
+ $ params ['transactionReference ' ] = ($ params ['token ' ]);
148
+ $ response = $ this ->gateway ->capture ($ this ->getCreditCardOptions ($ params , $ component ))
149
+ ->send ();
150
+ }
146
151
else {
147
152
$ response = $ this ->gateway ->purchase ($ this ->getCreditCardOptions ($ params , $ component ))
148
153
->send ();
@@ -195,7 +200,12 @@ public function setProcessorFields() {
195
200
$ this ->gateway ->$ fn ($ value );
196
201
}
197
202
if (in_array ('testMode ' , array_keys ($ this ->gateway ->getDefaultParameters ()))) {
198
- $ this ->gateway ->setTestMode ($ this ->_is_test );
203
+ if (method_exists ($ this ->gateway , 'setDeveloperMode ' )) {
204
+ $ this ->gateway ->setDeveloperMode ($ this ->_is_test );
205
+ }
206
+ else {
207
+ $ this ->gateway ->setTestMode ($ this ->_is_test );
208
+ }
199
209
}
200
210
}
201
211
catch (Exception $ e ) {
@@ -231,6 +241,17 @@ function getProcessorFields() {
231
241
return $ result ;
232
242
}
233
243
244
+ /**
245
+ * Get preapproval details that have been set.
246
+ *
247
+ * @param array $detail
248
+ *
249
+ * @return array mixed
250
+ */
251
+ function getPreApprovalDetails ($ detail ) {
252
+ return $ detail ;
253
+ }
254
+
234
255
/**
235
256
* Core specifically won't save billing address if you use notify mode so we make up for that here.
236
257
*
@@ -390,6 +411,7 @@ private function getCreditCardOptions($params, $component) {
390
411
'notifyUrl ' => $ this ->getNotifyUrl (),
391
412
'card ' => $ this ->getCreditCardObjectParams ($ params ),
392
413
'cardReference ' => CRM_Utils_Array::value ('token ' , $ params ),
414
+ 'transactionReference ' => CRM_Utils_Array::value ('token ' , $ params ),
393
415
);
394
416
if (!empty ($ params ['action ' ])) {
395
417
$ creditCardOptions ['action ' ] = 'Purchase ' ;
@@ -831,6 +853,76 @@ protected function supportsFutureRecurStartDate() {
831
853
return $ this ->_paymentProcessor ['is_recur ' ];
832
854
}
833
855
856
+ /**
857
+ * Is an authorize-capture flow supported.
858
+ *
859
+ * @return bool
860
+ */
861
+ protected function supportsPreApproval () {
862
+ $ entities = array ();
863
+ omnipaymultiprocessor_civicrm_managed ($ entities );
864
+ foreach ($ entities as $ entity ) {
865
+ if ($ entity ['entity ' ] === 'payment_processor_type ' ) {
866
+ if (!empty ($ entity ['params ' ]['supports_preapproval ' ])) {
867
+ return TRUE ;
868
+ }
869
+ }
870
+ }
871
+ return FALSE ;
872
+ }
873
+
874
+ /**
875
+ * Function to action pre-approval if supported
876
+ *
877
+ * @param array $params
878
+ * Parameters from the form
879
+ *
880
+ * This function returns an array which should contain
881
+ * - pre_approval_parameters (this will be stored on the calling form & available later)
882
+ * - redirect_url (if set the browser will be redirected to this.
883
+ *
884
+ * @return array
885
+ */
886
+ public function doPreApproval (&$ params ) {
887
+ $ this ->_component = 'contribute ' ;
888
+ $ this ->ensurePaymentProcessorTypeIsSet ();
889
+ $ this ->gateway = Omnipay::create (str_replace ('omnipay_ ' , '' , $ this ->_paymentProcessor ['payment_processor_type ' ]));
890
+ $ this ->setProcessorFields ();
891
+ $ this ->setTransactionID (CRM_Utils_Array::value ('contributionID ' , $ params ));
892
+ $ this ->storeReturnUrls ($ params ['qfKey ' ], CRM_Utils_Array::value ('participantID ' , $ params ), CRM_Utils_Array::value ('eventID ' , $ params ));
893
+ $ this ->saveBillingAddressIfRequired ($ params );
894
+
895
+ try {
896
+ $ response = $ this ->gateway ->authorize ($ this ->getCreditCardOptions ($ params , 'contribute ' ))
897
+ ->send ();
898
+ if ($ response ->isSuccessful ()) {
899
+ $ params ['trxn_id ' ] = $ params ['token ' ] = $ response ->getTransactionReference ();
900
+ $ creditCardPan = '************ ' . substr ($ params ['credit_card_number ' ], -4 );
901
+ foreach ($ _SESSION as $ key => $ value ) {
902
+ if (isset ($ value ['values ' ])) {
903
+ foreach ($ value ['values ' ] as $ pageName => $ pageValues ) {
904
+ if (isset ($ pageValues ['credit_card_number ' ])) {
905
+ unset($ _SESSION [$ key ]['values ' ][$ pageName ]['cvv2 ' ]);
906
+ $ _SESSION [$ key ]['values ' ][$ pageName ]['credit_card_number ' ] = $ creditCardPan ;
907
+ }
908
+ }
909
+ }
910
+ }
911
+ unset($ params ['credit_card_number ' ]);
912
+ unset($ params ['cvv2 ' ]);
913
+ return array (
914
+ 'pre_approval_parameters ' => array ('token ' => $ response ->getTransactionReference ())
915
+ );
916
+ }
917
+ else {
918
+ return $ this ->handleError ('alert ' , 'failed processor transaction ' . $ this ->_paymentProcessor ['payment_processor_type ' ], (array ) $ response , 9001 , $ response ->getMessage ());
919
+ }
920
+ } catch (\Exception $ e ) {
921
+ // internal error, log exception and display a generic message to the customer
922
+ return $ this ->handleError ('error ' , 'unknown processor error ' . $ this ->_paymentProcessor ['payment_processor_type ' ], array ($ e ->getCode () => $ e ->getMessage ()), $ e ->getCode (), 'Sorry, there was an error processing your payment. Please try again later. ' );
923
+ }
924
+ }
925
+
834
926
/**
835
927
* Get an array of the fields that can be edited on the recurring contribution.
836
928
*
0 commit comments