13 changed files
src | ||
API | ||
Payment | ||
MyFatoorahPayment.php | ||
MyFatoorahPaymentEmbedded.php | ||
MyFatoorahPaymentStatus.php | ||
MyFatoorahList.php | ||
MyFatoorahRefund.php | ||
MyFatoorahShipping.php | ||
MyFatoorahSupplier.php | ||
MyFatoorah.php | ||
MyFatoorahHelper.php | ||
autoload.php | ||
CHANGELOG.md | ||
composer.json | ||
README.md | ||
MyFatoorahPayment.php
/src/API/Payment/MyFatoorahPayment.php-35+35/src/API/Payment/MyFatoorahPayment.php
Add comment 9 * MyFatoorahPayment handles the payment process of MyFatoorah API endpoints
Add comment 10 *
Add comment 11 * @author MyFatoorah <tech@myfatoorah.com>
Add comment 12 Minus * @copyright 2021 MyFatoorah, All rights reserved
Add comment 12 Plus * @copyright MyFatoorah, All rights reserved
Add comment 13 * @license GNU General Public License v3.0
Add comment 14 */
Add comment 15 class MyFatoorahPayment extends MyFatoorah
Add comment 27 /**
Add comment 28 * List available Payment Methods (POST API)
Add comment 29 *
Add comment 30 Minus * @param double|int $invoiceValue Total invoice amount.
Add comment 31 Minus * @param string $displayCurrencyIso Total invoice currency.
Add comment 32 Minus * @param boolean $isCached It used to cache the gateways
Add comment 30 Plus * @param double|int $invoiceAmount The display invoice total amount.
Add comment 31 Plus * @param string $currencyIso The display invoice currency ISO.
Add comment 32 Plus * @param boolean $isCached It used to cache the gateways.
Add comment 33 *
Add comment 34 * @return array
Add comment 35 */
Add comment 36 Minus public function initiatePayment($invoiceValue = 0, $displayCurrencyIso = '', $isCached = false)
Add comment 36 Plus public function initiatePayment($invoiceAmount = 0, $currencyIso = '', $isCached = false)
Add comment 37 {
Add comment 38
Add comment 39 $postFields = [
Add comment 40 Minus 'InvoiceAmount' => $invoiceValue,
Add comment 41 Minus 'CurrencyIso' => $displayCurrencyIso,
Add comment 40 Plus 'InvoiceAmount' => $invoiceAmount,
Add comment 41 Plus 'CurrencyIso' => $currencyIso,
Add comment 42 ];
Add comment 43
Add comment 44 $json = $this->callAPI("$this->apiURL/v2/InitiatePayment", $postFields, null, 'Initiate Payment');
Add comment 74 /**
Add comment 75 * List available cached Payment Methods
Add comment 76 *
Add comment 77 Minus * @param bool $isAppleRegistered Is site domain is registered with applePay and MyFatoorah or not
Add comment 77 Plus * @param bool $isApRegistered Is site domain is registered with applePay and MyFatoorah or not
Add comment 78 *
Add comment 79 * @return array
Add comment 80 */
Add comment 81 Minus public function getCachedCheckoutGateways($isAppleRegistered = false)
Add comment 81 Plus public function getCachedCheckoutGateways($isApRegistered = false)
Add comment 82 {
Add comment 83
Add comment 84 $gateways = $this->getCachedVendorGateways();
Add comment 85
Add comment 86 Minus $cachedCheckoutGateways = ['all' => [], 'cards' => [], 'form' => [], 'ap' => [], 'gp' => []];
Add comment 86 Plus $cachedGateways = ['all' => [], 'cards' => [], 'form' => [], 'ap' => [], 'gp' => []];
Add comment 87 foreach ($gateways as $gateway) {
Add comment 88 Minus $cachedCheckoutGateways = $this->addGatewayToCheckoutGateways($gateway, $cachedCheckoutGateways, $isAppleRegistered);
Add comment 88 Plus $cachedGateways = $this->addGatewayToCheckout($gateway, $cachedGateways, $isApRegistered);
Add comment 89 }
Add comment 90
Add comment 91 Minus if ($isAppleRegistered) {
Add comment 91 Plus if ($isApRegistered) {
Add comment 92 //add only one ap gateway
Add comment 93 Minus $cachedCheckoutGateways['ap'] = $cachedCheckoutGateways['ap'][0] ?? [];
Add comment 93 Plus $cachedGateways['ap'] = $cachedGateways['ap'][0] ?? [];
Add comment 94 }
Add comment 95
Add comment 96 Minus return $cachedCheckoutGateways;
Add comment 96 Plus return $cachedGateways;
Add comment 97 }
Add comment 98
Add comment 99 //-----------------------------------------------------------------------------------------------------------------------------------------
Add comment 101 /**
Add comment 102 * Add the MyFatoorah gateway object to the a given Payment Methods Array
Add comment 103 *
Add comment 104 Minus * @param object $gateway MyFatoorah gateway object.
Add comment 105 Minus * @param array $checkoutGateways Payment Methods Array.
Add comment 106 Minus * @param boolean $isAppleRegistered Is site domain is registered with applePay and MyFatoorah or not.
Add comment 104 Plus * @param object $gateway MyFatoorah gateway object.
Add comment 105 Plus * @param array $checkoutGateways Payment Methods Array.
Add comment 106 Plus * @param boolean $isApRegistered Is site domain is registered with applePay and MyFatoorah or not.
Add comment 107 *
Add comment 108 * @return array
Add comment 109 */
Add comment 110 Minus protected function addGatewayToCheckoutGateways($gateway, $checkoutGateways, $isAppleRegistered)
Add comment 110 Plus protected function addGatewayToCheckout($gateway, $checkoutGateways, $isApRegistered)
Add comment 111 {
Add comment 112
Add comment 113 if ($gateway->PaymentMethodCode == 'gp') {
Add comment 114 $checkoutGateways['gp'] = $gateway;
Add comment 115 $checkoutGateways['all'][] = $gateway;
Add comment 116 } elseif ($gateway->PaymentMethodCode == 'ap') {
Add comment 117 Minus if ($isAppleRegistered) {
Add comment 117 Plus if ($isApRegistered) {
Add comment 118 $checkoutGateways['ap'][] = $gateway;
Add comment 119 } else {
Add comment 120 $checkoutGateways['cards'][] = $gateway;
Add comment 138 /**
Add comment 139 * Get Payment Method Object
Add comment 140 *
Add comment 141 Minus * @param string $gateway MyFatoorah gateway object.
Add comment 142 Minus * @param string $gatewayType The Search key ['PaymentMethodId', 'PaymentMethodCode'].
Add comment 143 Minus * @param double|int $invoiceValue Total invoice amount.
Add comment 144 Minus * @param string $displayCurrencyIso Total invoice currency.
Add comment 141 Plus * @param string $gateway MyFatoorah gateway object.
Add comment 142 Plus * @param string $searchKey The Search key ['PaymentMethodId', 'PaymentMethodCode'].
Add comment 143 Plus * @param double|int $invoiceAmount The display invoice total amount.
Add comment 144 Plus * @param string $currencyIso The display invoice currency ISO.
Add comment 145 *
Add comment 146 * @return object
Add comment 147 *
Add comment 148 * @throws Exception
Add comment 149 */
Add comment 150 Minus public function getOnePaymentMethod($gateway, $gatewayType = 'PaymentMethodId', $invoiceValue = 0, $displayCurrencyIso = '')
Add comment 150 Plus public function getOnePaymentMethod($gateway, $searchKey = 'PaymentMethodId', $invoiceAmount = 0, $currencyIso = '')
Add comment 151 {
Add comment 152
Add comment 153 Minus $paymentMethods = $this->initiatePayment($invoiceValue, $displayCurrencyIso);
Add comment 153 Plus $paymentMethods = $this->initiatePayment($invoiceAmount, $currencyIso);
Add comment 154
Add comment 155 $paymentMethod = null;
Add comment 156 foreach ($paymentMethods as $pm) {
Add comment 157 Minus if ($pm->$gatewayType == $gateway) {
Add comment 157 Plus if ($pm->$searchKey == $gateway) {
Add comment 158 $paymentMethod = $pm;
Add comment 159 break;
Add comment 160 }
Add comment 172 /**
Add comment 173 * Get the invoice/payment URL and the invoice id
Add comment 174 *
Add comment 175 Minus * @param array $curlData Invoice information.
Add comment 176 Minus * @param int|string $gatewayId MyFatoorah Gateway ID (default value: '0').
Add comment 177 Minus * @param int|string $orderId It used in log file (default value: null).
Add comment 178 Minus * @param string $sessionId The payment session used in embedded payment.
Add comment 179 Minus * @param string $notificationOption could be EML, SMS, LNK, or ALL.
Add comment 175 Plus * @param array $curlData Invoice information.
Add comment 176 Plus * @param int|string $gatewayId MyFatoorah Gateway ID (default value: '0').
Add comment 177 Plus * @param int|string $orderId It used in log file (default value: null).
Add comment 178 Plus * @param string $sessionId The payment session used in embedded payment.
Add comment 179 Plus * @param string $ntfOption The notificationOption for send payment. It could be EML, SMS, LNK, or ALL.
Add comment 180 *
Add comment 181 * @return array of invoiceURL and invoiceURL
Add comment 182 */
Add comment 183 Minus public function getInvoiceURL($curlData, $gatewayId = 0, $orderId = null, $sessionId = null, $notificationOption = 'Lnk')
Add comment 183 Plus public function getInvoiceURL($curlData, $gatewayId = 0, $orderId = null, $sessionId = null, $ntfOption = 'Lnk')
Add comment 184 {
Add comment 185
Add comment 186 $this->log('------------------------------------------------------------');
Add comment 194 return ['invoiceURL' => $data->PaymentURL, 'invoiceId' => $data->InvoiceId];
Add comment 195 } elseif ($gatewayId == 'myfatoorah' || empty($gatewayId)) {
Add comment 196 if (empty($curlData['NotificationOption'])) {
Add comment 197 Minus $curlData['NotificationOption'] = $notificationOption;
Add comment 197 Plus $curlData['NotificationOption'] = $ntfOption;
Add comment 198 }
Add comment 199
Add comment 200 $data = $this->sendPayment($curlData);
Add comment 230 /**
Add comment 231 * Create an Payment Link (POST API)
Add comment 232 *
Add comment 233 Minus * @param array $curlData Invoice information, check https://docs.myfatoorah.com/docs/execute-payment#required-fields.
Add comment 233 Plus * @param array $curlData Invoice information, check https://docs.myfatoorah.com/docs/execute-payment#request-model.
Add comment 234 *
Add comment 235 * @return object
Add comment 236 */
Add comment 239
Add comment 240 $this->preparePayment($curlData);
Add comment 241
Add comment 242 Minus $json = $this->callAPI("$this->apiURL/v2/ExecutePayment", $curlData, $curlData['CustomerReference'], 'Execute Payment'); //__FUNCTION__
Add comment 242 Plus $json = $this->callAPI("$this->apiURL/v2/ExecutePayment", $curlData, $curlData['CustomerReference'], 'Execute Payment');
Add comment 243 return $json->Data;
Add comment 244 }
Add comment 245
MyFatoorahPaymentEmbedded.php
/src/API/Payment/MyFatoorahPaymentEmbedded.php-20+22/src/API/Payment/MyFatoorahPaymentEmbedded.php
Add comment 8 * MyFatoorahPaymentForm handles the form process of MyFatoorah API endpoints
Add comment 9 *
Add comment 10 * @author MyFatoorah <tech@myfatoorah.com>
Add comment 11 Minus * @copyright 2021 MyFatoorah, All rights reserved
Add comment 11 Plus * @copyright MyFatoorah, All rights reserved
Add comment 12 * @license GNU General Public License v3.0
Add comment 13 */
Add comment 14 class MyFatoorahPaymentEmbedded extends MyFatoorahPayment
Add comment 26 /**
Add comment 27 * List available Payment Methods
Add comment 28 *
Add comment 29 Minus * @param double|int $invoiceValue Total invoice amount.
Add comment 30 Minus * @param string $displayCurrencyIso Total invoice currency.
Add comment 31 Minus * @param bool $isAppleRegistered Is site domain is registered with applePay and MyFatoorah or not.
Add comment 29 Plus * @param double|int $invoiceAmount The display invoice total amount.
Add comment 30 Plus * @param string $currencyIso The display invoice currency ISO.
Add comment 31 Plus * @param bool $isApRegistered Is site domain is registered with ApplePay and MyFatoorah or not.
Add comment 32 *
Add comment 33 * @return array
Add comment 34 */
Add comment 35 Minus public function getCheckoutGateways($invoiceValue, $displayCurrencyIso, $isAppleRegistered)
Add comment 35 Plus public function getCheckoutGateways($invoiceAmount, $currencyIso, $isApRegistered)
Add comment 36 {
Add comment 37
Add comment 38 if (!empty(self::$checkoutGateways)) {
Add comment 39 return self::$checkoutGateways;
Add comment 40 }
Add comment 41
Add comment 42 Minus $gateways = $this->initiatePayment($invoiceValue, $displayCurrencyIso);
Add comment 42 Plus $gateways = $this->initiatePayment($invoiceAmount, $currencyIso);
Add comment 43
Add comment 44 $mfListObj = new MyFatoorahList($this->config);
Add comment 45 $allRates = $mfListObj->getCurrencyRates();
Add comment 46 Minus $currencyRate = MyFatoorahList::getOneCurrencyRate($displayCurrencyIso, $allRates);
Add comment 46 Plus $currencyRate = MyFatoorahList::getOneCurrencyRate($currencyIso, $allRates);
Add comment 47
Add comment 48 self::$checkoutGateways = ['all' => [], 'cards' => [], 'form' => [], 'ap' => [], 'gp' => []];
Add comment 49 foreach ($gateways as $gateway) {
Add comment 55 'GatewayTransCurrency' => self::getTranslatedCurrency($gateway->PaymentCurrencyIso),
Add comment 56 ];
Add comment 57
Add comment 58 Minus self::$checkoutGateways = $this->addGatewayToCheckoutGateways($gateway, self::$checkoutGateways, $isAppleRegistered);
Add comment 58 Plus self::$checkoutGateways = $this->addGatewayToCheckout($gateway, self::$checkoutGateways, $isApRegistered);
Add comment 59 }
Add comment 60
Add comment 61 Minus if ($isAppleRegistered) {
Add comment 61 Plus if ($isApRegistered) {
Add comment 62 //add only one ap gateway
Add comment 63 Minus self::$checkoutGateways['ap'] = $this->getOneApplePayGateway(self::$checkoutGateways['ap'], $displayCurrencyIso, $allRates);
Add comment 63 Plus self::$checkoutGateways['ap'] = $this->getOneEmbeddedGateway(self::$checkoutGateways['ap'], $currencyIso, $allRates);
Add comment 64 }
Add comment 65
Add comment 66 return self::$checkoutGateways;
Add comment 80 private function getPaymentTotalAmount($paymentMethod, $allRates, $currencyRate)
Add comment 81 {
Add comment 82
Add comment 83 Plus $dbTrucVal = ((int) ($paymentMethod->TotalAmount * 1000)) / 1000;
Add comment 83 84 if ($paymentMethod->PaymentCurrencyIso == $paymentMethod->CurrencyIso) {
Add comment 84 Minus return $paymentMethod->TotalAmount;
Add comment 85 Plus return ceil($dbTrucVal * 100) / 100;
Add comment 85 86 }
Add comment 86 87
Add comment 87 88 //convert to portal base currency
Add comment 88 Minus $baseTotalAmount = ceil(((int) ($paymentMethod->TotalAmount * 100)) / $currencyRate) / 100;
Add comment 89 Plus $dueVal = ($currencyRate == 1) ? $dbTrucVal : round($paymentMethod->TotalAmount / $currencyRate, 3);
Add comment 90 Plus $baseTotalAmount = ceil($dueVal * 100) / 100;
Add comment 89 91
Add comment 90 92 //gateway currency is not the portal currency
Add comment 91 93 $paymentCurrencyRate = MyFatoorahList::getOneCurrencyRate($paymentMethod->PaymentCurrencyIso, $allRates);
Add comment 101 103 /**
Add comment 102 104 * Returns One Apple pay array in case multiple are enabled in the account
Add comment 103 105 *
Add comment 104 Minus * @param array $apGateways The all available AP gateways
Add comment 106 Plus * @param array $gateways The all available AP/GP gateways
Add comment 105 107 * @param string $displayCurrency The currency of the invoice total amount.
Add comment 106 108 * @param array $allRates The MyFatoorah currency rate array of all gateways.
Add comment 107 109 *
Add comment 108 110 * @return array
Add comment 109 111 */
Add comment 110 Minus protected function getOneApplePayGateway($apGateways, $displayCurrency, $allRates)
Add comment 112 Plus private function getOneEmbeddedGateway($gateways, $displayCurrency, $allRates)
Add comment 111 113 {
Add comment 112 114
Add comment 113 Minus $displayCurrencyIndex = array_search($displayCurrency, array_column($apGateways, 'PaymentCurrencyIso'));
Add comment 115 Plus $displayCurrencyIndex = array_search($displayCurrency, array_column($gateways, 'PaymentCurrencyIso'));
Add comment 114 116 if ($displayCurrencyIndex) {
Add comment 115 Minus return $apGateways[$displayCurrencyIndex];
Add comment 117 Plus return $gateways[$displayCurrencyIndex];
Add comment 116 118 }
Add comment 117 119
Add comment 118 120 //get defult mf account currency
Add comment 119 121 $defCurKey = array_search('1', array_column($allRates, 'Value'));
Add comment 120 122 $defaultCurrency = $allRates[$defCurKey]->Text;
Add comment 121 123
Add comment 122 Minus $defaultCurrencyIndex = array_search($defaultCurrency, array_column($apGateways, 'PaymentCurrencyIso'));
Add comment 124 Plus $defaultCurrencyIndex = array_search($defaultCurrency, array_column($gateways, 'PaymentCurrencyIso'));
Add comment 123 125 if ($defaultCurrencyIndex) {
Add comment 124 Minus return $apGateways[$defaultCurrencyIndex];
Add comment 126 Plus return $gateways[$defaultCurrencyIndex];
Add comment 125 127 }
Add comment 126 128
Add comment 127 Minus if (isset($apGateways[0])) {
Add comment 128 Minus return $apGateways[0];
Add comment 129 Plus if (isset($gateways[0])) {
Add comment 130 Plus return $gateways[0];
Add comment 129 131 }
Add comment 130 132
Add comment 131 133 return [];
MyFatoorahPaymentStatus.php
/src/API/Payment/MyFatoorahPaymentStatus.php-1+1/src/API/Payment/MyFatoorahPaymentStatus.php
Add comment 8 * MyFatoorahPaymentStatus handles the payment status of MyFatoorah API endpoints
Add comment 9 *
Add comment 10 * @author MyFatoorah <tech@myfatoorah.com>
Add comment 11 Minus * @copyright 2021 MyFatoorah, All rights reserved
Add comment 11 Plus * @copyright MyFatoorah, All rights reserved
Add comment 12 * @license GNU General Public License v3.0
Add comment 13 */
Add comment 14 class MyFatoorahPaymentStatus extends MyFatoorahPayment
Add comment 9 * MyFatoorahList handles the list process of MyFatoorah API endpoints
Add comment 10 *
Add comment 11 * @author MyFatoorah <tech@myfatoorah.com>
Add comment 12 Minus * @copyright 2021 MyFatoorah, All rights reserved
Add comment 12 Plus * @copyright MyFatoorah, All rights reserved
Add comment 13 * @license GNU General Public License v3.0
Add comment 14 */
Add comment 15 class MyFatoorahList extends MyFatoorah
Add comment 8 * MyFatoorahRefund handles the refund process of MyFatoorah API endpoints
Add comment 9 *
Add comment 10 * @author MyFatoorah <tech@myfatoorah.com>
Add comment 11 Minus * @copyright 2021 MyFatoorah, All rights reserved
Add comment 11 Plus * @copyright MyFatoorah, All rights reserved
Add comment 12 * @license GNU General Public License v3.0
Add comment 13 */
Add comment 14 class MyFatoorahRefund extends MyFatoorah
Add comment 21 *
Add comment 22 * @deprecated
Add comment 23 *
Add comment 24 Minus * @param int|string $keyId payment id that will be refunded
Add comment 25 Minus * @param double|int|string $amount the refund amount
Add comment 26 Minus * @param string $currencyCode the amount currency
Add comment 27 Minus * @param string $comment reason of the refund
Add comment 28 Minus * @param int|string $orderId used in log file (default value: null)
Add comment 29 Minus * @param string $keyType supported keys are (InvoiceId, PaymentId)
Add comment 24 Plus * @param int|string $keyId payment id that will be refunded
Add comment 25 Plus * @param double|int|string $amount the refund amount
Add comment 26 Plus * @param string $currency the amount currency
Add comment 27 Plus * @param string $comment reason of the refund
Add comment 28 Plus * @param int|string $orderId used in log file (default value: null)
Add comment 29 Plus * @param string $keyType supported keys are (InvoiceId, PaymentId)
Add comment 30 *
Add comment 31 * @return object
Add comment 32 */
Add comment 33 Minus public function refund($keyId, $amount, $currencyCode = null, $comment = null, $orderId = null, $keyType = 'PaymentId')
Add comment 33 Plus public function refund($keyId, $amount, $currency = null, $comment = null, $orderId = null, $keyType = 'PaymentId')
Add comment 34 {
Add comment 35 $postFields = [
Add comment 36 'Key' => $keyId,
Add comment 38 'RefundChargeOnCustomer' => false,
Add comment 39 'ServiceChargeOnCustomer' => false,
Add comment 40 'Amount' => $amount,
Add comment 41 Minus 'CurrencyIso' => $currencyCode,
Add comment 41 Plus 'CurrencyIso' => $currency,
Add comment 42 'Comment' => $comment,
Add comment 43 ];
Add comment 44
Add comment 8 * MyFatoorahShipping handles the shipping process of MyFatoorah API endpoints
Add comment 9 *
Add comment 10 * @author MyFatoorah <tech@myfatoorah.com>
Add comment 11 Minus * @copyright 2021 MyFatoorah, All rights reserved
Add comment 11 Plus * @copyright MyFatoorah, All rights reserved
Add comment 12 * @license GNU General Public License v3.0
Add comment 13 */
Add comment 14 class MyFatoorahShipping extends MyFatoorah