Created
March 2, 2014 23:43
-
-
Save rephseven/9315763 to your computer and use it in GitHub Desktop.
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
<?php | |
/* | |
Plugin Name: Personal Payment Gateway | |
Plugin URI: http://www.wpmembersistem.com | |
Description: Personal use only. | |
Version: 1.0 | |
Author: Arif Hidayanto | |
Author URI: http://www.wpmembersistem.com | |
License: GPL version 2 or later | |
*/ | |
// registers the gateway | |
function wpmembersistem_edd_register_gateway($gateways) { | |
$gateways['personal_gatewap'] = array('admin_label' => 'Personal Gateway', 'checkout_label' => __('Personal Gateway', 'wpmembersistem_edd')); | |
return $gateways; | |
} | |
add_filter('edd_payment_gateways', 'wpmembersistem_edd_register_gateway'); | |
function wpmembersistem_edd_personal_gatewap_cc_form() { | |
// register the action to remove default CC form | |
return; | |
} | |
add_action('edd_personal_gatewap_cc_form', 'wpmembersistem_edd_personal_gatewap_cc_form'); | |
// processes the payment | |
function wpmembersistem_edd_process_payment($purchase_data) { | |
global $edd_options; | |
/********************************** | |
* set transaction mode | |
**********************************/ | |
if(edd_is_test_mode()) { | |
// set test credentials here | |
} else { | |
// set live credentials here | |
} | |
/********************************** | |
* check for errors here | |
**********************************/ | |
/* | |
// errors can be set like this | |
if(!isset($_POST['card_number'])) { | |
// error code followed by error message | |
edd_set_error('empty_card', __('You must enter a card number', 'edd')); | |
} | |
*/ | |
// check for any stored errors | |
$errors = edd_get_errors(); | |
if(!$errors) { | |
$purchase_summary = edd_get_purchase_summary($purchase_data); | |
/********************************** | |
* setup the payment details | |
**********************************/ | |
$payment = array( | |
'price' => $purchase_data['price'], | |
'date' => $purchase_data['date'], | |
'user_email' => $purchase_data['user_email'], | |
'purchase_key' => $purchase_data['purchase_key'], | |
'currency' => $edd_options['currency'], | |
'downloads' => $purchase_data['downloads'], | |
'cart_details' => $purchase_data['cart_details'], | |
'user_info' => $purchase_data['user_info'], | |
'status' => 'pending' | |
); | |
// record the pending payment | |
$payment = edd_insert_payment($payment); | |
$merchant_payment_confirmed = false; | |
/********************************** | |
* Process the credit card here. | |
* If not using a credit card | |
* then redirect to merchant | |
* and verify payment with an IPN | |
**********************************/ | |
// if the merchant payment is complete, set a flag | |
$merchant_payment_confirmed = true; | |
if($merchant_payment_confirmed) { // this is used when processing credit cards on site | |
// once a transaction is successful, set the purchase to complete | |
edd_update_payment_status($payment, 'pending'); | |
// go to the success page | |
edd_send_to_success_page('instruction'); | |
} else { | |
$fail = true; // payment wasn't recorded | |
} | |
} else { | |
$fail = true; // errors were detected | |
} | |
if( $fail !== false ) { | |
// if errors are present, send the user back to the purchase page so they can be corrected | |
edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']); | |
} | |
} | |
add_action('edd_gateway_personal_gatewap', 'wpmembersistem_edd_process_payment'); | |
// adds the settings to the Payment Gateways section | |
function wpmembersistem_edd_add_settings($settings) { | |
$personal_gatewap_settings = array( | |
array( | |
'id' => 'personal_gatewap_settings', | |
'name' => '<strong>' . __('Personal Gateway Settings', 'wpmembersistem_edd') . '</strong>', | |
'desc' => __('Configure the gateway settings', 'wpmembersistem_edd'), | |
'type' => 'header' | |
), | |
array( | |
'id' => 'custom_message', | |
'name' => __('Message', 'pg_edd'), | |
'desc' => __('Write your message here', 'pg_edd'), | |
'type' => "textarea", | |
'std' => __('sample message', 'pg_edd' ), | |
'size' => 'regular' | |
), | |
); | |
return array_merge($settings, $personal_gatewap_settings); | |
} | |
add_filter('edd_settings_gateways', 'wpmembersistem_edd_add_settings'); | |
/** | |
* Register the payment icon | |
*/ | |
function wpmembersistem_edd_payment_icon($icons) { | |
$icons['http://localhost/lab8/wp-content/plugins/edd-personal-gateway/images/icon.png'] = 'Personal Gateway'; | |
return $icons; | |
} | |
add_filter('edd_accepted_payment_icons', 'wpmembersistem_edd_payment_icon'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment