Beispiel #1
0
/**
 * Create PayPal purchase
 *
 * @param int $post_id
 */
function aviators_submission_create_paypal_purchase($post_id)
{
    aviators_submission_paypal_payment_gateway();
    PayPal_Digital_Goods_Configuration::return_url(get_template_directory_uri() . '/aviators/plugins/submission/return.php?paypal=paid&post_id=' . $post_id);
    PayPal_Digital_Goods_Configuration::cancel_url(get_template_directory_uri() . '/aviators/plugins/submission/return.php?paypal=cancel&post_id=' . $post_id);
    PayPal_Digital_Goods_Configuration::notify_url(get_template_directory_uri() . '/aviators/plugins/submission/return.php?paypal=notify&post_id=' . $post_id);
    $post = get_post($post_id);
    $price = aviators_settings_get_value('submission', 'pay_per_post', 'price');
    $tax = aviators_settings_get_value('submission', 'pay_per_post', 'tax');
    $description = aviators_settings_get_value('submission', 'pay_per_post', 'description');
    $currency = aviators_settings_get_value('submission', 'pay_per_post', 'currency_code');
    $purchase_details = array('name' => get_bloginfo('name'), 'description' => get_bloginfo('description'), 'amount' => $price + $tax, 'tax_amount' => $tax, 'currency' => $currency, 'items' => array(array('item_name' => $post->post_title, 'item_description' => $description, 'item_amount' => $price, 'item_tax' => $tax, 'item_quantity' => 1, 'item_number' => $post_id)));
    return new PayPal_Purchase($purchase_details);
}
 /**
  * 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.
  * - version, string. The PayPal API version. Must be a minimum of 65.1. Default 76.0
  * 
  * @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()) {
         exit('You must specify your PayPal API username, password & signature in the $api_credentials array. For details of how to ');
     } elseif (empty($args['return_url']) && '' == PayPal_Digital_Goods_Configuration::username() || empty($args['cancel_url']) && '' == PayPal_Digital_Goods_Configuration::cancel_url()) {
         exit('You must specify a return_url & cancel_url.');
     }
     $defaults = array('sandbox' => true, 'version' => '76.0', '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());
     $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'];
 }
 /**
  * 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' => '', '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.');
    }
}