Created
July 12, 2019 13:50
-
-
Save ashleyfae/19317aef4bf55686e520aae1ff74ee57 to your computer and use it in GitHub Desktop.
RCP custom payment gateway WIP
This file contains hidden or 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
<?php | |
/** | |
* Authorize.net Payment Gateway | |
* | |
* @package rcp-authorize-net | |
* @copyright Copyright (c) 2019, Restrict Content Pro team | |
* @license GPL2+ | |
* @since 1.0 | |
*/ | |
namespace RCP\Anet; | |
use DateTime; | |
use Exception; | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; | |
} | |
class Payment_Gateway extends \RCP_Payment_Gateway { | |
/** | |
* @since 1.0 | |
* @var string | |
* @access private | |
*/ | |
private $api_login_id; | |
/** | |
* @since 1.0 | |
* @var string | |
* @access private | |
*/ | |
private $transaction_key; | |
/** | |
* @since 1.0 | |
* @var string | |
* @access private | |
*/ | |
private $transaction_signature; | |
/** | |
* Get things going | |
* | |
* @access public | |
* @since 1.0 | |
* @return void | |
*/ | |
public function init() { | |
global $rcp_options; | |
$this->supports[] = 'one-time'; | |
$this->supports[] = 'recurring'; | |
$this->supports[] = 'fees'; | |
$this->supports[] = 'trial'; | |
if ( $this->test_mode ) { | |
$this->api_login_id = isset( $rcp_options['authorize_test_api_login'] ) ? sanitize_text_field( $rcp_options['authorize_test_api_login'] ) : ''; | |
$this->transaction_key = isset( $rcp_options['authorize_test_txn_key'] ) ? sanitize_text_field( $rcp_options['authorize_test_txn_key'] ) : ''; | |
$this->transaction_signature = isset( $rcp_options['authorize_test_signature_key'] ) ? sanitize_text_field( $rcp_options['authorize_test_signature_key'] ) : ''; | |
} else { | |
$this->api_login_id = isset( $rcp_options['authorize_api_login'] ) ? sanitize_text_field( $rcp_options['authorize_api_login'] ) : ''; | |
$this->transaction_key = isset( $rcp_options['authorize_txn_key'] ) ? sanitize_text_field( $rcp_options['authorize_txn_key'] ) : ''; | |
$this->transaction_signature = isset( $rcp_options['authorize_signature_key'] ) ? sanitize_text_field( $rcp_options['authorize_signature_key'] ) : ''; | |
} | |
require_once RCP_ANET_PATH . 'vendor/autoload.php'; | |
} | |
/** | |
* Process registration | |
* | |
* @access public | |
* @since 1.0 | |
* @return void | |
*/ | |
public function process_signup() { | |
// Set up the query args | |
$args = array( | |
'price' => $this->initial_amount, // Includes initial price + signup fees + discounts. Just the base membership level price is $this->amount. | |
'description' => $this->subscription_name, // Name of the membership level. | |
'custom' => $this->membership->get_id(), // Store the membership ID as a unique identifier. | |
'email' => $this->email, // User's email address. | |
'return' => $this->return_url // Registration success URL. | |
); | |
// Set up auto renew subscription if applicable. | |
if( $this->auto_renew ) { | |
$args['interval'] = $this->length_unit; // month, day, year | |
$args['interval_count'] = $this->length; // 1, 2, 3, 4 . . . | |
} | |
// Redirect to the external payment page | |
wp_redirect( add_query_arg( $args, 'http://paymentpage.com/api/' ) ); | |
exit; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment