Stripe.php
70 lines
| 1 | <?php |
| 2 | namespace Give\Helpers\Gateways; |
| 3 | |
| 4 | /** |
| 5 | * Class Stripe |
| 6 | * |
| 7 | * @package Give\Helpers\Gateways |
| 8 | */ |
| 9 | class Stripe { |
| 10 | |
| 11 | /** |
| 12 | * Check whether the Account is configured or not. |
| 13 | * |
| 14 | * @since 2.7.0 |
| 15 | * @access public |
| 16 | * |
| 17 | * @return bool |
| 18 | */ |
| 19 | public static function isAccountConfigured() { |
| 20 | $publishableKey = give_stripe_get_publishable_key(); |
| 21 | $secretKey = give_stripe_get_secret_key(); |
| 22 | |
| 23 | return ! empty( $publishableKey ) || ! empty( $secretKey ); |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * This function is used to add Stripe account details to donation if donation process with any stripe payment method. |
| 28 | * |
| 29 | * @param int $donationId |
| 30 | * @param int $formId |
| 31 | * |
| 32 | * @since 2.7.0 |
| 33 | */ |
| 34 | public static function addAccountDetail( $donationId, $formId ) { |
| 35 | $accountId = give_stripe_get_default_account_slug( $formId ); |
| 36 | $accountDetail = give_stripe_get_default_account( $formId ); |
| 37 | $accountName = 'connect' === $accountDetail['type'] ? $accountDetail['account_name'] : give_stripe_convert_slug_to_title( $accountId ); |
| 38 | |
| 39 | $stripeAccountNote = 'connect' === $accountDetail['type'] ? |
| 40 | sprintf( |
| 41 | '%1$s "%2$s" %3$s', |
| 42 | esc_html__( 'Donation accepted with Stripe account', 'give' ), |
| 43 | "{$accountName} ({$accountId})", |
| 44 | esc_html__( 'using Stripe Connect.', 'give' ) |
| 45 | ) : |
| 46 | sprintf( |
| 47 | '%1$s "%2$s" %3$s', |
| 48 | esc_html__( 'Donation accepted with Stripe account', 'give' ), |
| 49 | $accountName, |
| 50 | esc_html__( 'using Manual API Keys.', 'give' ) |
| 51 | ); |
| 52 | |
| 53 | give_update_meta( $donationId, '_give_stripe_account_slug', $accountId ); |
| 54 | |
| 55 | // Log data to donation notes. |
| 56 | give_insert_payment_note( $donationId, $stripeAccountNote ); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Return whether or not a Stripe payment method. |
| 61 | * |
| 62 | * @param $paymentMethod |
| 63 | * |
| 64 | * @return bool |
| 65 | */ |
| 66 | public static function isDonationPaymentMethod( $paymentMethod ) { |
| 67 | return in_array( $paymentMethod, give_stripe_supported_payment_methods(), true ); |
| 68 | } |
| 69 | } |
| 70 |