示例#1
0
  Special thanks fly out to Drew Johnston (drewjoh.com) for phpPaypal.php.
 
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
 http://www.apache.org/licenses/LICENSE-2.0
 Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
*/
// Include phpPayPal class
include 'phpPayPal.php';
// Create instance of the phpPayPal class
$paypal = new phpPayPal(array('api_username' => '', 'api_password' => '', 'api_signature' => ''), true);
// Set your local currency code
$paypal->currency_code = 'EUR';
// Set the total amount for this order
// This may calculated dynamicly by using variables
$paypal->amount_total = '15';
// You can manually set the return and cancel URLs, or keep the one's pre-set in the class definition
$paypal->return_url = 'http://www.example.com/success.php';
$paypal->cancel_url = 'http://www.example.com/failed.php';
// $paypal->add_item('ItemName', 'ItemNumber', 'ItemQuantity', 'ItemTaxAmount', 'ItemPrice');
$paypal->add_item('SampleItem', 100, 1, 0, 15);
// Make the request
$paypal->set_express_checkout();
// If successful, we need to store the token, and then redirect the user to PayPal
if (!$paypal->_error) {
    // Store your token
    $fromPaypal = false;
}
$profile = $modx->user->getOne('Profile');
$user = array_merge($profile->toArray(), $modx->user->toArray());
if ($fromPaypal) {
    /* Check if we're in the sandbox or live and fetch the appropriate credentials */
    $p['sandbox'] = $modx->getOption('subscribeme.paypal.sandbox', null, true);
    if (!$p['sandbox']) {
        /* We're live */
        $paypal = new phpPayPal(false);
        $p['username'] = $modx->getOption('subscribeme.paypal.api_username');
        $p['password'] = $modx->getOption('subscribeme.paypal.api_password');
        $p['signature'] = $modx->getOption('subscribeme.paypal.api_signature');
    } else {
        /* We're using the sandbox */
        $paypal = new phpPayPal(true);
        $p['username'] = $modx->getOption('subscribeme.paypal.sandbox_username');
        $p['password'] = $modx->getOption('subscribeme.paypal.sandbox_password');
        $p['signature'] = $modx->getOption('subscribeme.paypal.sandbox_signature');
    }
    $paypal->API_USERNAME = $p['username'];
    $paypal->API_PASSWORD = $p['password'];
    $paypal->API_SIGNATURE = $p['signature'];
    $paypal->ip_address = $_SERVER['REMOTE_ADDR'];
    if ($debug) {
        var_dump(array('PayPal Settings' => $p, 'User' => $user));
    }
    /* Start filling in some data */
    $paypal->version = '57.0';
    $paypal->token = $_GET['token'];
    /* Get the users details */
示例#3
0
require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/classes/paypal/paypal.class.php';
$ppid = $modx->getOption('reference', $scriptProperties, '');
if (empty($ppid)) {
    return $modx->error->failure($modx->lexicon('sm.error.notspecified', array('what' => $modx->lexicon('sm.reference'))));
}
/* Check if we're in the sandbox or live and fetch the appropriate credentials */
$p['sandbox'] = $modx->getOption('subscribeme.paypal.sandbox', null, true);
if (!$p['sandbox']) {
    /* We're live */
    $paypal = new phpPayPal(false);
    $p['username'] = $modx->getOption('subscribeme.paypal.api_username');
    $p['password'] = $modx->getOption('subscribeme.paypal.api_password');
    $p['signature'] = $modx->getOption('subscribeme.paypal.api_signature');
} else {
    /* We're using the sandbox */
    $paypal = new phpPayPal(true);
    $p['username'] = $modx->getOption('subscribeme.paypal.sandbox_username');
    $p['password'] = $modx->getOption('subscribeme.paypal.sandbox_password');
    $p['signature'] = $modx->getOption('subscribeme.paypal.sandbox_signature');
}
$paypal->API_USERNAME = $p['username'];
$paypal->API_PASSWORD = $p['password'];
$paypal->API_SIGNATURE = $p['signature'];
$paypal->transaction_id = $ppid;
$paypal->version = '57.0';
//return $modx->error->failure($paypal->generateNVPString('GetRecurringPaymentsProfileDetails'));
$paypal->get_transaction_details();
//return $modx->error->failure(print_r($paypal->Response,true));
$response = $paypal->Response;
$return = array();
foreach ($response as $key => $value) {
示例#4
0
if (empty($ppid)) {
    return $modx->error->failure($modx->lexicon('sm.error.notspecified', array('what' => $modx->lexicon('sm.pp_profileid'))));
}
/* Init paypal */
require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/classes/paypal/paypal.class.php';
/* Check if we're in the sandbox or live and fetch the appropriate credentials */
$p['sandbox'] = $modx->getOption('subscribeme.paypal.sandbox', null, true);
if (!$p['sandbox']) {
    /* We're live */
    $paypal = new phpPayPal(false);
    $p['username'] = $modx->getOption('subscribeme.paypal.api_username');
    $p['password'] = $modx->getOption('subscribeme.paypal.api_password');
    $p['signature'] = $modx->getOption('subscribeme.paypal.api_signature');
} else {
    /* We're using the sandbox */
    $paypal = new phpPayPal(true);
    $p['username'] = $modx->getOption('subscribeme.paypal.sandbox_username');
    $p['password'] = $modx->getOption('subscribeme.paypal.sandbox_password');
    $p['signature'] = $modx->getOption('subscribeme.paypal.sandbox_signature');
}
$paypal->API_USERNAME = $p['username'];
$paypal->API_PASSWORD = $p['password'];
$paypal->API_SIGNATURE = $p['signature'];
$paypal->profile_id = $ppid;
$paypal->version = '57.0';
//$modx->log(MODX_LEVEL_ERROR,$paypal->generateNVPString('GetRecurringPaymentsProfileDetails'));
$paypal->get_recurring_payments_profile_details();
//return $modx->error->failure(print_r($paypal->Response,true));
if (strtolower($paypal->Response['STATUS']) != 'active' || strtolower($paypal->Response['STATUS']) != 'active') {
    return $modx->error->failure($modx->lexicon('sm.error.cancelsubscription.notactive', array('status' => $paypal->Response['STATUS'])));
}
 public function process($data, $config)
 {
     // Pass the store currency to the gateway
     $config["currency_code"] = $this->_config["currency"];
     // Create instance of the phpPayPal class
     $paypal = new phpPayPal($config);
     // (required)
     $paypal->ip_address = $_SERVER['REMOTE_ADDR'];
     // Order Totals (amount_total is required)
     $paypal->amount_total = $data["order_total"];
     $paypal->amount_tax = $data["cart_tax"];
     $paypal->amount_shipping = $data["cart_shipping"];
     // Credit Card Information (required)
     $paypal->credit_card_number = $data["autho_cc_num"];
     #$paypal->credit_card_type = 'Visa';
     $paypal->cvv2_code = $data["autho_cc_code"];
     $paypal->expire_date = $data["autho_cc_month"] . $data["autho_cc_year"];
     // Billing Details (required)
     $paypal->first_name = $data["br_billing_fname"];
     $paypal->last_name = $data["br_billing_lname"];
     $paypal->address1 = $data["br_billing_address1"];
     $paypal->address2 = $data["br_billing_address2"];
     $paypal->city = $data["br_billing_city"];
     $paypal->state = $data["br_billing_state"];
     $paypal->postal_code = $data["br_billing_zip"];
     $paypal->phone_number = $data["br_billing_phone"];
     $paypal->country_code = $data["br_billing_country"];
     // Shipping Details (NOT required)
     #$paypal->email = '*****@*****.**';
     $paypal->shipping_name = $data["br_shipping_fname"] . ' ' . $data["br_shipping_lname"];
     $paypal->shipping_address1 = $data["br_shipping_address1"];
     $paypal->shipping_address2 = $data["br_shipping_address2"];
     $paypal->shipping_city = $data["br_shipping_city"];
     $paypal->shipping_state = $data["br_shipping_state"];
     $paypal->shipping_postal_code = $data["br_shipping_zip"];
     $paypal->shipping_country_code = $data["br_shipping_country"];
     // Add Order Items (NOT required) - Name, Number, Qty, Tax, Amt
     // Repeat for each item needing to be added
     $total = 0;
     foreach ($data["cart"]["items"] as $item) {
         $p = number_format($item["price"], 2);
         $paypal->addItem($item["title"], $item["product_id"], $item["quantity"], 0, $p);
         $total += $item["quantity"] * $p;
     }
     if ($data["cart_discount"] != 0) {
         $d = number_format($data["cart_discount"] * -1, 2);
         $paypal->addItem('Discount', 'Discount', 1, 0, $d);
         $total += $d;
     }
     // Perform the payment
     $paypal->do_direct_payment();
     $resp = $paypal->Response;
     // Get the card type from the number
     $card_type = cc_type_number($data["autho_cc_num"]);
     if (strtoupper($resp["ACK"]) != "SUCCESS" && strtoupper($resp["ACK"]) != "SUCCESSWITHWARNING") {
         $trans = array('error' => $resp["L_LONGMESSAGE0"]);
     } else {
         //Check for subscriptions
         $subscription = array();
         foreach ($data["cart"]["items"] as $item) {
             if ($item["type_id"] == 6) {
                 $subResp = $this->create_subscription($item, $data, $config);
                 $subArr = $this->_parse_return($subResp);
                 if ($subArr[1] == 'Ok') {
                     $subscription[] = array_merge($item, $subArr);
                 } else {
                     #debug print_r($arr);
                 }
             }
         }
         // Set the transaction details into
         // a serialized array for posting to
         // the order
         $details = array("Method" => "PayPal Pro", "Card Type" => $card_type, "Card" => 'XXXX' . substr($data["autho_cc_num"], -4, 4), "Approval Code" => $resp["CORRELATIONID"], "Transaction ID" => $resp["TRANSACTIONID"]);
         // Return the trans details
         $trans = array('status' => 3, 'transaction_id' => $resp["TRANSACTIONID"], 'payment_card' => 'XXXX' . substr($data["autho_cc_num"], -4, 4), 'payment_type' => 'Authorize', 'amount' => $data["order_total"], 'details' => serialize($details), 'approval' => $resp["CORRELATIONID"], 'subscription' => $subscription);
     }
     return $trans;
 }
示例#6
0
require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/classes/paypal/paypal.class.php';
$ppid = $modx->getOption('profileid', $scriptProperties, '');
if (empty($ppid)) {
    return $modx->error->failure($modx->lexicon('sm.error.notspecified', array('what' => 'ID')));
}
/* Check if we're in the sandbox or live and fetch the appropriate credentials */
$p['sandbox'] = $modx->getOption('subscribeme.paypal.sandbox', null, true);
if (!$p['sandbox']) {
    /* We're live */
    $paypal = new phpPayPal(false);
    $p['username'] = $modx->getOption('subscribeme.paypal.api_username');
    $p['password'] = $modx->getOption('subscribeme.paypal.api_password');
    $p['signature'] = $modx->getOption('subscribeme.paypal.api_signature');
} else {
    /* We're using the sandbox */
    $paypal = new phpPayPal(true);
    $p['username'] = $modx->getOption('subscribeme.paypal.sandbox_username');
    $p['password'] = $modx->getOption('subscribeme.paypal.sandbox_password');
    $p['signature'] = $modx->getOption('subscribeme.paypal.sandbox_signature');
}
$paypal->API_USERNAME = $p['username'];
$paypal->API_PASSWORD = $p['password'];
$paypal->API_SIGNATURE = $p['signature'];
$paypal->profile_id = $ppid;
$paypal->version = '57.0';
//return $modx->error->failure($paypal->generateNVPString('GetRecurringPaymentsProfileDetails'));
$paypal->get_recurring_payments_profile_details();
//return $modx->error->failure(print_r($paypal->Response,true));
$response = $paypal->Response;
$return = array();
foreach ($response as $key => $value) {
示例#7
0
$p['currency_code'] = $modx->getOption('subscribeme.currencycode', null, 'USD');
$p['amount'] = $product->get('price');
$p['return_url'] = $modx->makeUrl($modx->getOption('return_id', $scriptProperties, $modx->getOption('subscribeme.paypal.return_id')), '', '', 'full');
$p['cancel_url'] = $modx->makeUrl($modx->getOption('cancel_id', $scriptProperties, $modx->getOption('subscribeme.paypal.cancel_id')), '', array('transid' => $subid), 'full');
$p['fail_id'] = $modx->getOption('fail_id', $scriptProperties, $modx->getOption('subscribeme.paypal.fail_id'));
/* Check if we're in the sandbox or live and fetch the appropriate credentials */
$p['sandbox'] = $modx->getOption('subscribeme.paypal.sandbox', null, true);
if (!$p['sandbox']) {
    /* We're live */
    $paypal = new phpPayPal(false);
    $p['username'] = $modx->getOption('subscribeme.paypal.api_username');
    $p['password'] = $modx->getOption('subscribeme.paypal.api_password');
    $p['signature'] = $modx->getOption('subscribeme.paypal.api_signature');
} else {
    /* We're using the sandbox */
    $paypal = new phpPayPal(true);
    $p['username'] = $modx->getOption('subscribeme.paypal.sandbox_username');
    $p['password'] = $modx->getOption('subscribeme.paypal.sandbox_password');
    $p['signature'] = $modx->getOption('subscribeme.paypal.sandbox_signature');
}
$paypal->API_USERNAME = $p['username'];
$paypal->API_PASSWORD = $p['password'];
$paypal->API_SIGNATURE = $p['signature'];
$paypal->ip_address = $_SERVER['REMOTE_ADDR'];
/* Prepare order / transaction data */
$profile = $modx->user->getOne('Profile');
$user = array_merge($profile->toArray(), $modx->user->toArray());
$prod = $product->toArray();
$sub = $subscription->toArray();
if ($debug) {
    var_dump(array('PayPal Settings' => $p, 'User' => $user, 'Product' => $prod, 'Subscription' => $sub));
$p = array();
$p['currency_code'] = $modx->getOption('subscribeme.currencycode', null, 'USD');
$p['amount'] = $prod['price'];
$p['return_url'] = $modx->makeUrl($hook->formit->config['completedResource'], '', '', 'full');
$p['fail_id'] = $hook->formit->config['errorResource'];
/* Check if we're in the sandbox or live and fetch the appropriate credentials */
$p['sandbox'] = $modx->getOption('subscribeme.paypal.sandbox', null, true);
if (!$p['sandbox']) {
    /* We're live */
    $paypal = new phpPayPal(false);
    $p['username'] = $modx->getOption('subscribeme.paypal.api_username');
    $p['password'] = $modx->getOption('subscribeme.paypal.api_password');
    $p['signature'] = $modx->getOption('subscribeme.paypal.api_signature');
} else {
    /* We're using the sandbox */
    $paypal = new phpPayPal(true);
    $p['username'] = $modx->getOption('subscribeme.paypal.sandbox_username');
    $p['password'] = $modx->getOption('subscribeme.paypal.sandbox_password');
    $p['signature'] = $modx->getOption('subscribeme.paypal.sandbox_signature');
}
$paypal->API_USERNAME = $p['username'];
$paypal->API_PASSWORD = $p['password'];
$paypal->API_SIGNATURE = $p['signature'];
$paypal->ip_address = $_SERVER['REMOTE_ADDR'];
if ($debug) {
    var_dump(array('PayPal Settings' => $p, 'Transaction' => $trans, 'Product' => $prod, 'Subscription' => $sub));
}
/* Start filling in some data */
$paypal->version = '57.0';
$paypal->token = $token;
/* Set recurring payment information */
示例#9
0
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
 http://www.apache.org/licenses/LICENSE-2.0
 Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
*/
// Include phpPayPal class
include 'phpPayPal.php';
// Include phpPayPal class
include 'phpPayPal.php';
// Create instance of the phpPayPal class
$paypal = new phpPayPal(array('api_username' => '', 'api_password' => '', 'api_signature' => ''), true);
// Store the token and PayerID sent by PayPal
$paypal->token = $_GET['token'];
$paypal->payer_id = $_GET['PayerID'];
// Transfer the money to the seller
$paypal->do_express_checkout_payment();
// If successful, we need to store the token, and then redirect the user to PayPal
if (!$paypal->_error && $paypal->get_transaction_details()) {
    /*
     * if ("COMPLETED" == $paypal->payment_status && ("SUCCESS" == $paypal->ack || "SUCCESSWITHWARNING" == $paypal->ack)) {
     * 
     *     Call additional functions
     * 
     * }
     */
} else {