Easy Digital Downloads
  • Package
  • Function
  • Tree

Packages

  • EDD
    • Admin
      • Actions
      • Add-ons
      • Dashboard
      • Discounts
      • Downloads
      • Export
      • Notices
      • Pages
      • Payments
      • Reports
      • Settings
      • System
      • Upgrades
      • Upload
      • Welcome
    • Cart
    • Checkout
    • Classes
      • API
      • Fees
      • HTML
      • Roles
      • Session
    • Emails
    • Functions
      • AJAX
      • Compatibility
      • Errors
      • Formatting
      • Install
      • Login
      • Taxes
      • Templates
    • Gateways
    • Logging
    • Payments
    • Shortcodes
    • Widgets

Functions

  • edd_get_chosen_gateway
  • edd_get_default_gateway
  • edd_get_enabled_payment_gateways
  • edd_get_gateway_admin_label
  • edd_get_gateway_checkout_label
  • edd_get_payment_gateways
  • edd_get_paypal_page_style
  • edd_get_paypal_redirect
  • edd_is_gateway_active
  • edd_listen_for_paypal_ipn
  • edd_load_ajax_gateway
  • edd_manual_payment
  • edd_manual_remove_cc_form
  • edd_no_gateway_error
  • edd_process_paypal_ipn
  • edd_process_paypal_purchase
  • edd_process_paypal_refund
  • edd_process_paypal_web_accept
  • edd_record_gateway_error
  • edd_send_to_gateway
  • edd_show_gateways
  1 <?php
  2 /**
  3  * Gateway Functions
  4  *
  5  * @package     EDD
  6  * @subpackage  Gateways
  7  * @copyright   Copyright (c) 2013, Pippin Williamson
  8  * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
  9  * @since       1.0
 10  */
 11 
 12 // Exit if accessed directly
 13 if ( ! defined( 'ABSPATH' ) ) exit;
 14 
 15 /**
 16  * Returns a list of all available gateways.
 17  *
 18  * @since 1.0
 19  * @return array $gateways All the available gateways
 20  */
 21 function edd_get_payment_gateways() {
 22     // Default, built-in gateways
 23     $gateways = array(
 24         'paypal' => array( 'admin_label' => 'PayPal', 'checkout_label' => 'PayPal' ),
 25         'manual' => array( 'admin_label' => __( 'Test Payment', 'edd' ), 'checkout_label' => __( 'Test Payment', 'edd' ) ),
 26     );
 27 
 28     return apply_filters( 'edd_payment_gateways', $gateways );
 29 }
 30 
 31 /**
 32  * Returns a list of all enabled gateways.
 33  *
 34  * @since 1.0
 35  * @return array $gateway_list All the available gateways
 36 */
 37 function edd_get_enabled_payment_gateways() {
 38     global $edd_options;
 39 
 40     $gateways = edd_get_payment_gateways();
 41     $enabled_gateways = isset( $edd_options['gateways'] ) ? $edd_options['gateways'] : false;
 42 
 43     $gateway_list = array();
 44 
 45     foreach ( $gateways as $key => $gateway ) :
 46         if ( isset( $enabled_gateways[ $key ] ) && $enabled_gateways[ $key ] == 1) :
 47             $gateway_list[ $key ] = $gateway;
 48         endif;
 49     endforeach;
 50 
 51     return $gateway_list;
 52 }
 53 
 54 /**
 55  * Checks whether a specified gateway is activated.
 56  *
 57  * @since 1.0
 58  * @param string $gateway Name of the gateway to check for
 59  * @return boolean true if enabled, false otherwise
 60 */
 61 function edd_is_gateway_active( $gateway ) {
 62     $gateways = edd_get_enabled_payment_gateways();
 63 
 64     if ( array_key_exists( $gateway, $gateways ) ) {
 65         return true;
 66     }
 67 
 68     return false;
 69 }
 70 
 71 /**
 72  * Gets the default payment gateway selected from the EDD Settings
 73  *
 74  * @since 1.5
 75  * @global $edd_options Array of all the EDD Options
 76  * @return string Gateway ID
 77  */
 78 function edd_get_default_gateway() {
 79     global $edd_options;
 80     return isset( $edd_options['default_gateway'] ) && edd_is_gateway_active( $edd_options['default_gateway'] ) ? $edd_options['default_gateway'] : 'paypal';
 81 }
 82 
 83 /**
 84  * Returns the admin label for the specified gateway
 85  *
 86  * @since 1.0.8.3
 87  * @param string $gateway Name of the gateway to retrieve a label for
 88  * @return string Gateway admin label
 89  */
 90 function edd_get_gateway_admin_label( $gateway ) {
 91     $gateways = edd_get_enabled_payment_gateways();
 92     return isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['admin_label'] : $gateway;
 93 }
 94 
 95 /**
 96  * Returns the checkout label for the specified gateway
 97  *
 98  * @since 1.0.8.5
 99  * @param string $gateway Name of the gateway to retrieve a label for
100  * @return string Checkout label for the gateway
101  */
102 function edd_get_gateway_checkout_label( $gateway ) {
103     $gateways = edd_get_enabled_payment_gateways();
104     return isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['checkout_label'] : $gateway;
105 }
106 
107 /**
108  * Sends all the payment data to the specified gateway
109  *
110  * @since 1.0
111  * @param string $gateway Name of the gateway
112  * @param array $payment_data All the payment data to be sent to the gateway
113  * @return void
114 */
115 function edd_send_to_gateway( $gateway, $payment_data ) {
116     // $gateway must match the ID used when registering the gateway
117     do_action( 'edd_gateway_' . $gateway, $payment_data );
118 }
119 
120 /**
121  * Determines if the gateway menu should be shown
122  *
123  * If the cart amount is zero, no option is shown and the cart uses the manual gateway
124  * to emulate a no-gateway-setup for a free download
125  *
126  * @since 1.3.2
127  * @return bool $show_gateways Whether or not to show the gateways
128  */
129 function edd_show_gateways() {
130     $gateways = edd_get_enabled_payment_gateways();
131     $show_gateways = false;
132 
133     if ( count( $gateways ) > 1 && ! isset( $_GET['payment-mode'] ) ) {
134         $show_gateways = true;
135         if ( edd_get_cart_amount() <= 0 ) {
136             $show_gateways = false;
137         }
138     }
139 
140     return apply_filters( 'edd_show_gateways', $show_gateways );
141 }
142 
143 /**
144  * Determines what the currently selected gateway is
145  *
146  * If the cart amount is zero, no option is shown and the cart uses the manual
147  * gateway to emulate a no-gateway-setup for a free download
148  *
149  * @access public
150  * @since 1.3.2
151  * @return string $enabled_gateway The slug of the gateway
152  */
153 function edd_get_chosen_gateway() {
154     $gateways = edd_get_enabled_payment_gateways();
155 
156     if ( isset( $_GET['payment-mode'] ) ) {
157         $enabled_gateway = urldecode( $_GET['payment-mode'] );
158     } else if( count( $gateways ) >= 1 && ! isset( $_GET['payment-mode'] ) ) {
159         foreach ( $gateways as $gateway_id => $gateway ):
160             $enabled_gateway = $gateway_id;
161             if ( edd_get_cart_amount() <= 0 ) {
162                 $enabled_gateway = 'manual'; // This allows a free download by filling in the info
163             }
164         endforeach;
165     } else if ( edd_get_cart_amount() <= 0 ) {
166         $enabled_gateway = 'manual';
167     } else {
168         $enabled_gateway = 'none';
169     }
170 
171     return apply_filters( 'edd_chosen_gateway', $enabled_gateway );
172 }
173 
174 /**
175  * Record a gateway error
176  *
177  * A simple wrapper function for edd_record_log()
178  *
179  * @access public
180  * @since 1.3.3
181  * @param string $title Title of the log entry (default: empty)
182  * @param string $message  Message to store in the log entry (default: empty)
183  * @param int $parent Parent log entry (default: 0)
184  * @return int ID of the new log entry
185  */
186 function edd_record_gateway_error( $title = '', $message = '', $parent = 0 ) {
187     return edd_record_log( $title, $message, $parent, 'gateway_error' );
188 }
189 
190 /**
191  * Sets an error on checkout if no gateways are enabled
192  *
193  * @since 1.3.4
194  * @return void
195  */
196 function edd_no_gateway_error() {
197     $gateways = edd_get_enabled_payment_gateways();
198 
199     if ( empty( $gateways ) )
200         edd_set_error( 'no_gateways', __( 'You must enable a payment gateway to use Easy Digital Downloads', 'edd' ) );
201     else
202         edd_unset_error( 'no_gateways' );
203 }
204 add_action( 'init', 'edd_no_gateway_error' );
205 
206 /**
207  * Loads a payment gateway via AJAX
208  *
209  * @since 1.3.4
210  * @return void
211  */
212 function edd_load_ajax_gateway() {
213     if ( isset( $_POST['edd_payment_mode'] ) ) {
214         do_action( 'edd_purchase_form' );
215         exit();
216     }
217 }
218 add_action( 'wp_ajax_edd_load_gateway', 'edd_load_ajax_gateway' );
219 add_action( 'wp_ajax_nopriv_edd_load_gateway', 'edd_load_ajax_gateway' );
Easy Digital Downloads API documentation generated by ApiGen 2.8.0