Beispiel #1
1
/**
 * Payment gateway
 */
function aviators_submission_paypal_payment_gateway()
{
    $payment_gateway = aviators_settings_get_value('submission', 'common', 'payment_gateway');
    if ($payment_gateway == 'paypal') {
        require_once AVIATORS_DIR . "/libraries/paypal-digital-goods/paypal-digital-goods.class.php";
        require_once AVIATORS_DIR . "/libraries/paypal-digital-goods/paypal-configuration.class.php";
        require_once AVIATORS_DIR . "/libraries/paypal-digital-goods/paypal-purchase.class.php";
        if (aviators_settings_get_value('submission', 'paypal', 'sandbox') == 'on') {
            $username = aviators_settings_get_value('submission', 'paypal', 'sandbox_username');
            $password = aviators_settings_get_value('submission', 'paypal', 'sandbox_password');
            $signature = aviators_settings_get_value('submission', 'paypal', 'sandbox_signature');
        } else {
            $username = aviators_settings_get_value('submission', 'paypal', 'username');
            $password = aviators_settings_get_value('submission', 'paypal', 'password');
            $signature = aviators_settings_get_value('submission', 'paypal', 'signature');
            PayPal_Digital_Goods_Configuration::environment('live');
        }
        PayPal_Digital_Goods_Configuration::username($username);
        PayPal_Digital_Goods_Configuration::password($password);
        PayPal_Digital_Goods_Configuration::signature($signature);
        PayPal_Digital_Goods_Configuration::business_name(get_bloginfo('name'));
    }
}
 /**
  * Creates a PayPal Digital Goods Object configured according to the parameters in the args associative array. 
  * 
  * Available $args parameters:
  * - cancel_url, string, required. The URL on your site that the purchaser is sent to when cancelling a payment during the checkout process.
  * - return_url, string, required. The URL on your site that the purchaser is sent to upon completing checkout.
  * - notify_url, string, optional. The URL for receiving Instant Payment Notification (IPN) about this transaction. 
  * - solution_type, string, optional. Type of checkout flow. It is one of Sole (default, buyer does not need to create a PayPal account to check out) or Mark (buyer must have a PayPal account to check out)
  * - sandbox, boolean. Flag to indicate whether to use the PayPal Sandbox or live PayPal site. Default true - use sandbox.
  * - business_name, string. A label that overrides the business name in the PayPal account on the PayPal hosted checkout pages.
  * 
  * @param api_credentials, required, a name => value array containing your API username, password and signature.
  * @param args, named parameters to customise the subscription and checkout process. See description for available parameters.
  */
 public function __construct($args = array())
 {
     if ('' == PayPal_Digital_Goods_Configuration::username() || '' == PayPal_Digital_Goods_Configuration::password() || '' == PayPal_Digital_Goods_Configuration::signature()) {
         throw new Exception('You must specify your PayPal API username, password & signature in the $api_credentials array.');
     } elseif (empty($args['return_url']) && '' == PayPal_Digital_Goods_Configuration::username() || empty($args['cancel_url']) && '' == PayPal_Digital_Goods_Configuration::cancel_url()) {
         throw new Exception('You must specify a return_url & cancel_url.');
     }
     $defaults = array('sandbox' => true, 'business_name' => PayPal_Digital_Goods_Configuration::business_name(), 'solution_type' => 'Sole', 'return_url' => PayPal_Digital_Goods_Configuration::return_url(), 'cancel_url' => PayPal_Digital_Goods_Configuration::cancel_url(), 'notify_url' => PayPal_Digital_Goods_Configuration::notify_url(), 'display_address' => PayPal_Digital_Goods_Configuration::display_address(), 'locale_code' => PayPal_Digital_Goods_Configuration::locale_code());
     $args = array_merge($defaults, $args);
     $this->currency = PayPal_Digital_Goods_Configuration::currency();
     $this->business_name = $args['business_name'];
     $this->return_url = $args['return_url'];
     $this->cancel_url = $args['cancel_url'];
     $this->notify_url = $args['notify_url'];
     $this->solution_type = $args['solution_type'];
     $this->display_address = $args['display_address'];
     $this->locale_code = $args['locale_code'];
 }
/**
 * A central function for settings the credentials for both subscription & purchase 
 * objects with the PayPal_Digital_Goods_Configuration registry class.
 */
function set_credentials()
{
    /*
    PayPal_Digital_Goods_Configuration::username( 'your_api_username' );
    PayPal_Digital_Goods_Configuration::password( 'your_api_password' );
    PayPal_Digital_Goods_Configuration::signature( 'your_api_signature' );
    */
    PayPal_Digital_Goods_Configuration::username('digita_1308916325_biz_api1.gmail.com');
    PayPal_Digital_Goods_Configuration::password('1308916362');
    PayPal_Digital_Goods_Configuration::signature('AFnwAcqRkyW0yPYgkjqTkIGqPbSfAyVFbnFAjXCRltVZFzlJyi2.HbxW');
    PayPal_Digital_Goods_Configuration::return_url(get_script_uri('return.php?paypal=paid'));
    PayPal_Digital_Goods_Configuration::cancel_url(get_script_uri('return.php?paypal=cancel'));
    PayPal_Digital_Goods_Configuration::business_name('Demo Store');
    PayPal_Digital_Goods_Configuration::notify_url(get_script_uri('return.php?paypal=notify'));
    // Uncomment the line below to switch to the live PayPal site
    //PayPal_Digital_Goods_Configuration::environment( 'live' );
    if (PayPal_Digital_Goods_Configuration::username() == 'your_api_username' || PayPal_Digital_Goods_Configuration::password() == 'your_api_password' || PayPal_Digital_Goods_Configuration::signature() == 'your_api_signature') {
        exit('You must set your API credentials in ' . __FILE__ . ' for this example to work.');
    }
}