4 * Payment Gateways for credit card transactions
7 * @link https://www.open-emr.org
8 * @author Jerry Padgett <sjpadgett@gmail.com>
9 * @copyright Copyright (c) 2019 Jerry Padgett <sjpadgett@gmail.com>
10 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
13 namespace OpenEMR\Billing
;
16 use Omnipay\Common\CreditCard
;
17 use OpenEMR\Common\Crypto\CryptoGen
;
24 private $transactionKey;
27 public function __construct($name)
29 $this->production
= !$GLOBALS['gateway_mode_production'];
31 $cryptoGen = new CryptoGen();
32 $this->apiKey
= $cryptoGen->decryptStandard($GLOBALS['gateway_api_key']);
33 $this->transactionKey
= $cryptoGen->decryptStandard($GLOBALS['gateway_transaction_key']);
35 // Setup payment Gateway
36 $this->setGateway($name);
39 public function setApiKey($key)
44 public function setTransactionKey($key)
46 $this->transactionKey
= $key;
49 public function setProduction($tf)
51 $this->production
= $tf;
59 * $card['expiremonth'] = '';
60 * $card['expireyear'] = '';
63 public function setCard($card)
66 $ccard = new CreditCard($card);
70 } catch (\Exception
$ex) {
71 return $ex->getMessage();
79 public function submitPaymentCard($pay)
82 // Send purchase request
83 $response = $this->gateway
->purchase(
85 'amount' => $pay['amount'],
86 'currency' => $pay['currency'],
91 if ($response->isSuccessful()) {
93 } elseif ($response->isRedirect()) {
94 // Redirect to offsite payment gateway
95 return $response->getMessage();
98 return $response->getMessage();
100 } catch (\Exception
$ex) {
101 return $ex->getMessage();
107 * @return bool|string
109 public function submitPaymentToken($pay)
112 // Send purchase request with card token
113 $response = $this->gateway
->purchase($pay)->send();
115 if ($response->isSuccessful()) {
117 } elseif ($response->isRedirect()) {
118 // Redirect to offsite payment gateway
119 return $response->getMessage();
122 return $response->getMessage();
124 } catch (\Exception
$ex) {
125 return $ex->getMessage();
133 public function setGateway($which)
135 if (isset($this->gateway
)) {
136 unset($this->gateway
);
139 if (stripos($which, "stripe") !== false) {
140 $gatewayName = 'Stripe';
141 $this->gateway
= Omnipay
::create($gatewayName);
142 $this->gateway
->setApiKey($this->apiKey
);
144 $gatewayName = 'AuthorizeNetApi_Api';
145 $this->gateway
= Omnipay
::create($gatewayName);
146 $this->gateway
->setAuthName($this->apiKey
);
147 $this->gateway
->setTransactionKey($this->transactionKey
);
148 $this->gateway
->setTestMode($this->production
);
150 } catch (\Exception
$ex) {
151 return $ex->getMessage();