← All changes
|
app/Modules/PaymentMethods/StripeGateway/StripeHelper.php
+38
-0
1.3.21
→
1.6.6
View file →
| @@ -127,8 +127,46 @@ | ||
| 127 | 127 | return $subscriptionUpdateData; |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | |
| 131 | + /** | |
| 132 | + * Convert a Stripe wire amount (invoice/charge/payment_intent) to FluentCart's | |
| 133 | + * internal ×100 unit. Zero-decimal currencies (JPY, KRW, ...) come off the wire | |
| 134 | + * unscaled, so they need the ×100 that non-zero-decimal currencies already have. | |
| 135 | + * | |
| 136 | + * @param int|float $amount | |
| 137 | + * @param string $currency | |
| 138 | + * @return int | |
| 139 | + */ | |
| 140 | + public static function toInternalAmount($amount, $currency) | |
| 141 | + { | |
| 142 | + $amount = (int)$amount; | |
| 143 | + | |
| 144 | + if ($currency && CurrenciesHelper::isZeroDecimal($currency)) { | |
| 145 | + $amount *= 100; | |
| 146 | + } | |
| 147 | + | |
| 148 | + return $amount; | |
| 149 | + } | |
| 150 | + | |
| 151 | + /** | |
| 152 | + * Convert a Stripe object's `livemode` flag to a getStripeObject()/getApiKey() | |
| 153 | + * `$mode` argument. The store's global mode toggle ('current') is not a reliable | |
| 154 | + * proxy for which key an already-fetched object needs — use its own livemode | |
| 155 | + * whenever one is available instead of guessing from the store setting. | |
| 156 | + * | |
| 157 | + * @param bool|null $livemode Null when no prior object/event is available yet. | |
| 158 | + * @return string 'live', 'test', or 'current' | |
| 159 | + */ | |
| 160 | + public static function modeFromLivemode($livemode) | |
| 161 | + { | |
| 162 | + if (is_null($livemode)) { | |
| 163 | + return 'current'; | |
| 164 | + } | |
| 165 | + | |
| 166 | + return $livemode ? 'live' : 'test'; | |
| 167 | + } | |
| 168 | + | |
| 131 | 169 | public static function processRemoteRefund($transaction, $amount, $args) |
| 132 | 170 | { |
| 133 | 171 | $intentId = $transaction->vendor_charge_id; |
| 134 | 172 | if (!$intentId) { |