public static function paypalpro_validation($validation_result) { $config = self::is_ready_for_capture($validation_result); if (!$config) { return $validation_result; } require_once self::get_base_path() . "/data.php"; // Determine if feed specific api settings are enabled $local_api_settings = array(); if ($config["meta"]["api_settings_enabled"] == 1) { $local_api_settings = self::get_local_api_settings($config); } // Billing $card_field = self::get_creditcard_field($validation_result["form"]); $card_number = rgpost("input_{$card_field["id"]}_1"); $card_type = GFCommon::get_card_type($card_number); $expiration_date = rgpost("input_{$card_field["id"]}_2"); $country = rgpost('input_' . str_replace(".", "_", $config["meta"]["customer_fields"]["country"])); $country = class_exists('GF_Field_Address') ? GF_Fields::get('address')->get_country_code($country) : GFCommon::get_country_code($country); $billing = array(); $billing['CREDITCARDTYPE'] = $card_type["slug"]; $billing['ACCT'] = $card_number; $billing['EXPDATE'] = $expiration_date[0] . $expiration_date[1]; $billing['CVV2'] = rgpost("input_{$card_field["id"]}_3"); $billing['STREET'] = rgpost('input_' . str_replace(".", "_", $config["meta"]["customer_fields"]["address1"])); $billing['STREET2'] = rgpost('input_' . str_replace(".", "_", $config["meta"]["customer_fields"]["address2"])); $billing['CITY'] = rgpost('input_' . str_replace(".", "_", $config["meta"]["customer_fields"]["city"])); $billing['STATE'] = rgpost('input_' . str_replace(".", "_", $config["meta"]["customer_fields"]["state"])); $billing['ZIP'] = rgpost('input_' . str_replace(".", "_", $config["meta"]["customer_fields"]["zip"])); $billing['COUNTRYCODE'] = $country == "UK" ? "GB" : $country; $billing['CURRENCYCODE'] = GFCommon::get_currency(); // Customer Contact $billing['FIRSTNAME'] = rgpost('input_' . str_replace(".", "_", $config["meta"]["customer_fields"]["first_name"])); $billing['LASTNAME'] = rgpost('input_' . str_replace(".", "_", $config["meta"]["customer_fields"]["last_name"])); $billing['EMAIL'] = rgpost('input_' . str_replace(".", "_", $config["meta"]["customer_fields"]["email"])); $lead = RGFormsModel::create_lead($validation_result["form"]); $product_billing_data = self::get_product_billing_data($validation_result["form"], $lead, $config); $amount = $product_billing_data["amount"]; $products = $product_billing_data["products"]; $billing = array_merge($billing, $product_billing_data["billing"]); if ($config["meta"]["type"] == "product") { if ($amount == 0) { //blank out credit card field if this is the last page if (self::is_last_page($validation_result["form"])) { $_POST["input_{$card_field["id"]}_1"] = ""; } //creating dummy transaction response if there are any visible product fields in the form if (self::has_visible_products($validation_result["form"])) { self::$transaction_response = array("transaction_id" => "N/A", "amount" => 0, "transaction_type" => 1, 'config_id' => $config['id']); } return $validation_result; } //setting up a one time payment $ip = RGFormsModel::get_ip(); $billing['PAYMENTACTION'] = "Sale"; $billing['IPADDRESS'] = $ip == "::1" ? "127.0.0.1" : $ip; $billing['RETURNFMFDETAILS'] = "1"; $billing['BUTTONSOURCE'] = 'gravityforms'; $billing['AMT'] = $amount; $billing['NOTIFYURL'] = get_bloginfo("url") . "/?page=gf_paypalpro_ipn"; self::log_debug("Sending one time payment."); $response = self::post_to_paypal("DoDirectPayment", $billing, $local_api_settings, $validation_result["form"], $lead); if (!empty($response) && !empty($response["TRANSACTIONID"])) { self::$transaction_response = array("transaction_id" => $response["TRANSACTIONID"], "subscription_amount" => 0, "initial_payment_amount" => $response["AMT"], "transaction_type" => 1, 'config_id' => $config['id']); self::log_debug("Payment successful."); return $validation_result; } else { // Payment was not succesful, need to display error message self::log_error("Payment was NOT successful."); return self::set_validation_result($validation_result, $_POST, $response, "capture"); } } else { //setting up a recurring payment $billing['PROFILESTARTDATE'] = gmdate(DATE_ATOM); $billing['SUBSCRIBERNAME'] = $billing['FIRSTNAME'] . " " . $billing['LASTNAME']; $billing['MAXFAILEDPAYMENTS'] = "0"; $interval_unit = self::get_interval_unit($config["meta"]["billing_cycle_type"]); $interval_length = $config["meta"]["billing_cycle_number"]; $billing['BILLINGPERIOD'] = $interval_unit; $billing['BILLINGFREQUENCY'] = $interval_length; $billing['TOTALBILLINGCYCLES'] = $config["meta"]["recurring_times"]; $billing['AMT'] = $amount; //setup fee $setup_fee_amount = 0; if ($config["meta"]["setup_fee_enabled"]) { $setup_fee_product = rgar($products["products"], $config["meta"]["setup_fee_amount_field"]); if (!empty($setup_fee_product)) { $setup_fee_amount = self::get_product_price($setup_fee_product); $billing['INITAMT'] = $setup_fee_amount; } } //trial $trial_amount = 0; if ($config["meta"]["trial_period_enabled"]) { if ($config["meta"]["trial_type"] == "paid") { $trial_product = rgar($products["products"], $config["meta"]["trial_amount_field"]); $trial_amount = empty($trial_product) ? 0 : self::get_product_price($trial_product); $billing["TRIALAMT"] = $trial_amount; } $billing["TRIALBILLINGPERIOD"] = self::get_interval_unit($config["meta"]["trial_period_type"]); $billing["TRIALBILLINGFREQUENCY"] = $config["meta"]["trial_period_number"]; $billing["TRIALTOTALBILLINGCYCLES"] = $config["meta"]["trial_recurring_times"]; } self::log_debug("Sending recurring payment to PayPal."); $response = self::post_to_paypal("CreateRecurringPaymentsProfile", $billing, $local_api_settings, $validation_result["form"], $lead); if (!empty($response) && !empty($response["PROFILEID"])) { self::$transaction_response = array("transaction_id" => rgar($response, "TRANSACTIONID"), "subscription_id" => $response["PROFILEID"], "subscription_amount" => $billing['AMT'], "initial_payment_amount" => $setup_fee_amount, "transaction_type" => 2, 'config_id' => $config['id']); self::log_debug("Recurring payment setup successful."); return $validation_result; } else { // Payment was not successful, need to display error message self::log_error("Recurring payment was NOT successful."); return self::set_validation_result($validation_result, $_POST, $response, "recurring"); } } }