-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from dszubart/feature/SP-590
Updated plugin to use EDD 3.1 and support PHP 8.0
- Loading branch information
Showing
264 changed files
with
36,413 additions
and
785 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Test | ||
|
||
on: | ||
push: | ||
pull_request: | ||
types: | ||
- opened | ||
- reopened | ||
|
||
jobs: | ||
phpcs: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
php-version: [ 8.0, 8.1, 8.2 ] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: php-actions/composer@v6 | ||
with: | ||
php_version: ${{ matrix.php-version }} | ||
args: --ignore-platform-reqs | ||
- name: Run WordPress code standard | ||
run: | | ||
./vendor/bin/phpcs --ignore=vendor,wpcs --standard=./phpcs.xml ./ |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
namespace BitPayEddLib; | ||
|
||
use wpdb; | ||
|
||
class BitPayCheckoutTransactions { | ||
|
||
private string $table_name = '_bitpay_checkout_transactions'; | ||
|
||
public function create_table(): void { | ||
$charset_collate = $this->get_wpdb()->get_charset_collate(); | ||
$query = "CREATE TABLE IF NOT EXISTS $this->table_name( | ||
`id` int(11) NOT NULL AUTO_INCREMENT, | ||
`order_id` int(11) NOT NULL, | ||
`transaction_id` varchar(255) NOT NULL, | ||
`transaction_status` varchar(50) NOT NULL DEFAULT 'new', | ||
`date_added` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
PRIMARY KEY (`id`) | ||
) $charset_collate;"; | ||
|
||
require_once ABSPATH . 'wp-admin/includes/upgrade.php'; | ||
dbDelta( $query ); | ||
} | ||
|
||
public function update_status( | ||
string $event_name, | ||
int $order_id, | ||
string $transaction_id | ||
): void { | ||
$query = $this->get_wpdb()->prepare( | ||
'UPDATE ' . $this->table_name . ' SET transaction_status = %s WHERE order_id = %s AND transaction_id = %s', | ||
$event_name, | ||
$order_id, | ||
$transaction_id | ||
); | ||
$this->get_wpdb()->query( $query ); | ||
} | ||
|
||
public function update_last_pending_status( | ||
string $event_name, | ||
int $order_id | ||
): void { | ||
$query = $this->get_wpdb()->prepare( | ||
'UPDATE ' . $this->table_name . ' SET transaction_status = %s' | ||
. ' WHERE order_id = %s AND transaction_status = %s order by date_added desc limit 1', | ||
$event_name, | ||
$order_id, | ||
'pending' | ||
); | ||
$this->get_wpdb()->query( $query ); | ||
} | ||
|
||
public function create_transaction( | ||
int $order_id, | ||
string $transaction_id, | ||
string $status | ||
): void { | ||
$query = $this->get_wpdb()->prepare( | ||
'INSERT INTO ' . $this->table_name . ' (order_id,transaction_id,transaction_status) VALUES(%s,%s,%s)', | ||
$order_id, | ||
$transaction_id, | ||
$status | ||
); | ||
$this->get_wpdb()->query( $query ); | ||
} | ||
|
||
private function get_wpdb(): wpdb { | ||
global $wpdb; | ||
return $wpdb; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace BitPayEddLib; | ||
|
||
use BitPaySDK\Client; | ||
use BitPaySDK\Env; | ||
use BitPaySDK\Exceptions\BitPayException; | ||
use BitPaySDK\PosClient; | ||
|
||
class BitPayClientFactory { | ||
|
||
/** | ||
* Create PosClient | ||
* | ||
* @throws BitPayException BitPayException class. | ||
*/ | ||
public function create(): Client { | ||
return new PosClient( $this->get_bitpay_token(), $this->get_environment() ); | ||
} | ||
|
||
private function get_bitpay_token(): string { | ||
/* dev or prod token */ | ||
switch ( $this->get_option( 'test_mode' ) ) { | ||
case 'true': | ||
case '1': | ||
default: | ||
return $this->get_option( 'bitpay_checkout_token_dev' ); | ||
case 'false': | ||
case '0': | ||
return $this->get_option( 'bitpay_checkout_token_prod' ); | ||
} | ||
} | ||
|
||
private function get_environment(): string { | ||
switch ( $this->get_option( 'test_mode' ) ) { | ||
case 'true': | ||
case '1': | ||
default: | ||
return Env::TEST; | ||
case 'false': | ||
case '0': | ||
return Env::PROD; | ||
} | ||
} | ||
|
||
private function get_option( string $option_name ): string { | ||
global $edd_options; | ||
|
||
return $edd_options[ $option_name ]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace BitPayEddLib; | ||
|
||
use WP_REST_Request; | ||
|
||
class BitPayEddAbandonOrder { | ||
private BitPayCheckoutTransactions $bitpay_checkout_transactions; | ||
|
||
public function __construct( BitPayCheckoutTransactions $bitpay_checkout_transactions ) { | ||
$this->bitpay_checkout_transactions = $bitpay_checkout_transactions; | ||
} | ||
|
||
public function execute( WP_REST_Request $request ): void { | ||
$data = $request->get_params(); | ||
$order_id = $data['orderid']; | ||
|
||
$this->bitpay_checkout_transactions->update_last_pending_status( 'invoice_expired', $order_id ); | ||
edd_update_order_status( $order_id, 'abandoned' ); | ||
|
||
require_once ABSPATH . 'wp-admin/includes/upgrade.php'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
|
||
namespace BitPayEddLib; | ||
|
||
class BitPayEddAddSettings { | ||
|
||
public function execute( array $gateway_settings ): array { | ||
$gateway_settings['bp_checkout_edd'] = $this->get_settings(); | ||
|
||
return $gateway_settings; | ||
} | ||
|
||
private function get_settings(): array { | ||
$setting = array( | ||
array( | ||
'id' => 'bp_checkout_edd_settings', | ||
'name' => '<strong>' . __( 'BitPay Checkout for Easy Digital Downloads', 'pw_edd' ) . '</strong>', | ||
'desc' => __( 'Configure your BitPay integration', 'pw_edd' ), | ||
'type' => 'header', | ||
), | ||
array( | ||
'id' => 'bp_checkout_edd_desc', | ||
'name' => '', | ||
'type' => 'descriptive_text', | ||
'desc' => __( | ||
'If you have not created a BitPay Merchant Token, you can create one on your BitPay Dashboard.<br><a href = "https://test.bitpay.com/dashboard/merchant/api-tokens" target = "_blank">(Test)</a> or <a href= "https://www.bitpay.com/dashboard/merchant/api-tokens" target = "_blank">(Production)</a> </p><br>To switch between the development and production environment, enable/disable <strong>Test Mode</strong> on the <a href = "edit.php?post_type=download&page=edd-settings&tab=gateways§ion=main">Payment Gateways</a> page.', | ||
'pw_edd' | ||
), | ||
), | ||
array( | ||
'id' => 'bitpay_checkout_token_dev', | ||
'name' => __( 'Development Token', 'pw_edd' ), | ||
'desc' => __( | ||
'<br>Your <b>development</b> merchant token. <a href = "https://test.bitpay.com/dashboard/merchant/api-tokens" target = "_blank">Create one here</a>.', | ||
'pw_edd' | ||
), | ||
'type' => 'text', | ||
'size' => 'regular', | ||
), | ||
array( | ||
'id' => 'bitpay_checkout_token_prod', | ||
'name' => __( 'Production Token', 'pw_edd' ), | ||
'desc' => __( | ||
'<br>Your <b>production</b> merchant token. <a href = "https://www.bitpay.com/dashboard/merchant/api-tokens" target = "_blank">Create one here</a>.', | ||
'pw_edd' | ||
), | ||
'type' => 'text', | ||
'size' => 'regular', | ||
), | ||
array( | ||
'id' => 'bitpay_checkout_capture_email', | ||
'name' => __( 'Auto-Capture Email', 'pw_edd' ), | ||
'desc' => __( | ||
'<br>Should BitPay try to auto-add the client\'s email address? If <b>Yes</b>, the client will not be able to change the email address on the BitPay invoice. If <b>No</b>, they will be able to add their own email address when paying the invoice.', | ||
'pw_edd' | ||
), | ||
'type' => 'select', | ||
'size' => 'regular', | ||
'options' => $this->get_checkout_capture_email_options(), | ||
|
||
), | ||
array( | ||
'id' => 'bitpay_checkout_flow', | ||
'name' => __( 'Checkout Flow', 'pw_edd' ), | ||
'desc' => sprintf( | ||
/* translators: %s is replaced by "get_bloginfo" function */ | ||
__( | ||
'<br>If this is set to <b>Redirect</b>, then the customer will be redirected to <b>BitPay</b> to checkout, and return to the checkout page once the payment is made.<br>If this is set to <b>Modal</b>, the user will stay on <b>%s</b> and complete the transaction.', | ||
'pw_edd' | ||
), | ||
get_bloginfo( 'name', null ) | ||
), | ||
'type' => 'select', | ||
'size' => 'regular', | ||
'options' => $this->get_checkout_flow_options(), | ||
|
||
), | ||
); | ||
|
||
return apply_filters( 'edd_bp_checkout_settings', $setting ); | ||
} | ||
|
||
private function get_checkout_flow_options(): array { | ||
$options = array( | ||
'1' => __( 'Modal', 'easy-digital-downloads' ), | ||
'2' => __( 'Redirect', 'easy-digital-downloads' ), | ||
); | ||
|
||
return apply_filters( 'bpcedd_cflow', $options ); | ||
} | ||
|
||
private function get_checkout_capture_email_options(): array { | ||
$options = array( | ||
'0' => __( 'No', 'easy-digital-downloads' ), | ||
'1' => __( 'Yes', 'easy-digital-downloads' ), | ||
); | ||
|
||
return apply_filters( 'bpcedd_get_yes_no', $options ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace BitPayEddLib; | ||
|
||
class BitPayEddPrintEnqueueScripts { | ||
|
||
public function execute(): void { | ||
/* phpcs:ignore */ | ||
wp_enqueue_script( 'remote-bitpayquickpay-js', 'https://bitpay.com/bitpay.min.js', null, null, true ); | ||
wp_enqueue_script( 'bitpayquickpay-js', plugins_url( '../js/bitpay_edd.js', __FILE__ ), null, wp_rand( 111, 999 ), false ); | ||
$mode = BitPayEndpoint::get_type( $this->get_option( 'test_mode' ) ); | ||
?> | ||
<script type="text/javascript"> | ||
if (window.location.href.indexOf("&bpedd=1&invoiceID=") > -1) { | ||
setTimeout(function () { | ||
jQuery('#primary').css('opacity', '0.3'); | ||
}, | ||
200 | ||
); | ||
|
||
var urlParams = new URLSearchParams(window.location.search); | ||
var $oid = urlParams.get('order_id') | ||
var $iid = urlParams.get('invoiceID') | ||
$cart_url = "<?php echo esc_js( edd_get_checkout_uri() ); ?>" | ||
$fix_url = "<?php echo esc_js( get_home_url() . '/wp-json/bitpay-edd/cartfix/update' ); ?>" | ||
|
||
setTimeout(function () { | ||
showBPInvoice('<?php echo esc_js( $mode ); ?>', $iid, $oid, $cart_url, $fix_url) | ||
}, | ||
250 | ||
); | ||
} | ||
</script> | ||
<?php | ||
} | ||
|
||
private function get_option( string $option_name ): string { | ||
global $edd_options; | ||
|
||
return $edd_options[ $option_name ]; | ||
} | ||
} |
Oops, something went wrong.