本文整理匯總了PHP中GFCommon::get_country_code方法的典型用法代碼示例。如果您正苦於以下問題:PHP GFCommon::get_country_code方法的具體用法?PHP GFCommon::get_country_code怎麽用?PHP GFCommon::get_country_code使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類GFCommon
的用法示例。
在下文中一共展示了GFCommon::get_country_code方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: get_full_address
protected function get_full_address($entry, $field_id)
{
$street_value = str_replace(" ", " ", trim($entry[$field_id . ".1"]));
$street2_value = str_replace(" ", " ", trim($entry[$field_id . ".2"]));
$city_value = str_replace(" ", " ", trim($entry[$field_id . ".3"]));
$state_value = str_replace(" ", " ", trim($entry[$field_id . ".4"]));
$zip_value = trim($entry[$field_id . ".5"]);
$country_value = GFCommon::get_country_code(trim($entry[$field_id . ".6"]));
$address = $street_value;
$address .= !empty($address) && !empty($street2_value) ? " {$street2_value}" : $street2_value;
$address .= !empty($address) && (!empty($city_value) || !empty($state_value)) ? ", {$city_value}," : $city_value;
$address .= !empty($address) && !empty($city_value) && !empty($state_value) ? " {$state_value}" : $state_value;
$address .= !empty($address) && !empty($zip_value) ? " {$zip_value}," : $zip_value;
$address .= !empty($address) && !empty($country_value) ? " {$country_value}" : $country_value;
return $address;
}
示例2: customer_query_string
public function customer_query_string($feed, $entry)
{
$fields = '';
foreach ($this->get_customer_fields() as $field) {
$field_id = $feed['meta'][$field['meta_name']];
$value = rgar($entry, $field_id);
if ($field['name'] == 'country') {
$value = class_exists('GF_Field_Address') ? GF_Fields::get('address')->get_country_code($value) : GFCommon::get_country_code($value);
} elseif ($field['name'] == 'state') {
$value = class_exists('GF_Field_Address') ? GF_Fields::get('address')->get_us_state_code($value) : GFCommon::get_us_state_code($value);
}
if (!empty($value)) {
$fields .= "&{$field['name']}=" . urlencode($value);
}
}
return $fields;
}
示例3: customer_query_string
private static function customer_query_string($config, $lead)
{
$fields = "";
foreach (self::get_customer_fields() as $field) {
$field_id = $config["meta"]["customer_fields"][$field["name"]];
$value = rgar($lead, $field_id);
if ($field["name"] == "country") {
$value = GFCommon::get_country_code($value);
} else {
if ($field["name"] == "state") {
$value = GFCommon::get_us_state_code($value);
}
}
if (!empty($value)) {
$fields .= "&{$field["name"]}=" . urlencode($value);
}
}
return $fields;
}
示例4: process_merge_vars
/**
* During export, create an export array based on the feed mappings.
* @param array $entry Entry array
* @param array $form Form array
* @param array $feed Feed array
* @return [type] [description]
*/
private static function process_merge_vars($entry, $form, $feed)
{
self::log_debug('process_merge_vars(): Starting...');
$merge_vars = array();
foreach ($feed["meta"]["field_map"] as $var_tag => $field_id) {
$field = RGFormsModel::get_field($form, $field_id);
$input_type = RGFormsModel::get_input_type($field);
if ($var_tag == 'address_full') {
$merge_vars[$var_tag] = self::get_address($entry, $field_id);
} else {
if ($var_tag == 'country') {
$merge_vars[$var_tag] = empty($entry[$field_id]) ? '' : GFCommon::get_country_code(trim($entry[$field_id]));
} else {
if (isset($entry[$field_id]) && $entry[$field_id] === "0") {
$merge_vars[$var_tag] = "0";
} else {
if ($var_tag != "email") {
if (!empty($entry[$field_id]) && !($entry[$field_id] == "0")) {
switch ($input_type) {
// Thanks to Scott Kingsley Clark
// http://wordpress.org/support/topic/likert-field-compatibility-with-survey-add-on
case 'likert':
$value = $entry[$field_id];
foreach ($field['choices'] as $choice) {
if ($value === $choice['value']) {
$value = $choice['text'];
break;
}
}
$value = htmlspecialchars($value);
break;
case 'multiselect':
// If there are commas in the value, this makes it so it can be comma exploded.
// Values cannot contain semicolons: http://boards.developerforce.com/t5/NET-Development/Salesforce-API-inserting-values-into-multiselect-fields-using/td-p/125910
foreach ($field['choices'] as $choice) {
$entry[$field_id] = str_replace($choice, str_replace(',', ',', $choice), $entry[$field_id]);
}
// Break into an array
$elements = explode(",", $entry[$field_id]);
// We decode first so that the commas are commas again, then
// implode the array to be picklist format for SF
$value = implode(';', array_map('html_entity_decode', array_map('htmlspecialchars', $elements)));
break;
default:
$value = htmlspecialchars($entry[$field_id]);
}
$merge_vars[$var_tag] = GFCommon::replace_variables($value, $form, $entry, false, false, false);
} else {
if (array_key_exists($field_id, self::$foreign_keys)) {
$merge_vars[$var_tag] = self::$foreign_keys[$field_id];
} else {
// This is for checkboxes
$elements = array();
foreach ($entry as $key => $value) {
if (floor($key) == floor($field_id) && !empty($value)) {
$elements[] = htmlspecialchars($value);
}
}
$value = implode(';', array_map('htmlspecialchars', $elements));
$merge_vars[$var_tag] = GFCommon::replace_variables($value, $form, $entry, false, false, false);
}
}
}
}
}
}
$merge_vars[$var_tag] = apply_filters('gf_salesforce_mapped_value_' . $var_tag, $merge_vars[$var_tag], $field, $var_tag, $form, $entry);
$merge_vars[$var_tag] = apply_filters('gf_salesforce_mapped_value', $merge_vars[$var_tag], $field, $var_tag, $form, $entry);
}
self::log_debug('process_merge_vars(): Completed.');
return $merge_vars;
}
示例5: get_address
private function get_address($entry, $field_id)
{
$street_value = str_replace(' ', ' ', trim(rgar($entry, $field_id . '.1')));
$street2_value = str_replace(' ', ' ', trim(rgar($entry, $field_id . '.2')));
$city_value = str_replace(' ', ' ', trim(rgar($entry, $field_id . '.3')));
$state_value = str_replace(' ', ' ', trim(rgar($entry, $field_id . '.4')));
$zip_value = trim(rgar($entry, $field_id . '.5'));
$country_value = trim(rgar($entry, $field_id . '.6'));
if (!empty($country_value)) {
$country_value = class_exists('GF_Field_Address') ? GF_Fields::get('address')->get_country_code($country_value) : GFCommon::get_country_code($country_value);
}
$address = array(!empty($street_value) ? $street_value : '-', $street2_value, !empty($city_value) ? $city_value : '-', !empty($state_value) ? $state_value : '-', !empty($zip_value) ? $zip_value : '-', $country_value);
return implode(' ', $address);
}
示例6: create
private function create($entry, $form, $feed, $api)
{
$merge_vars = array();
foreach ($feed["meta"]["field_map"] as $var_tag => $field_id) {
$field = RGFormsModel::get_field($form, $field_id);
$input_type = RGFormsModel::get_input_type($field);
if ($var_tag == 'address_full') {
$merge_vars[$var_tag] = self::get_address($entry, $field_id);
} else {
if ($var_tag == 'country') {
$merge_vars[$var_tag] = empty($entry[$field_id]) ? '' : GFCommon::get_country_code(trim($entry[$field_id]));
} else {
if ($entry[$field_id] === "0") {
$merge_vars[$var_tag] = "0";
} else {
if ($var_tag != "email") {
if (!empty($entry[$field_id]) && !($entry[$field_id] == "0")) {
switch ($input_type) {
case 'multiselect':
// If there are commas in the value, this makes it so it can be comma exploded.
// Values cannot contain semicolons: http://boards.developerforce.com/t5/NET-Development/Salesforce-API-inserting-values-into-multiselect-fields-using/td-p/125910
foreach ($field['choices'] as $choice) {
$entry[$field_id] = str_replace($choice, str_replace(',', ',', $choice), $entry[$field_id]);
}
// Break into an array
$elements = explode(",", $entry[$field_id]);
// We decode first so that the commas are commas again, then
// implode the array to be picklist format for SF
$merge_vars[$var_tag] = implode(';', array_map('html_entity_decode', array_map('htmlspecialchars', $elements)));
break;
default:
$merge_vars[$var_tag] = htmlspecialchars($entry[$field_id]);
}
} else {
// This is for checkboxes
$elements = array();
foreach ($entry as $key => $value) {
if (floor($key) == floor($field_id) && !empty($value)) {
$elements[] = htmlspecialchars($value);
}
}
$merge_vars[$var_tag] = implode(';', array_map('htmlspecialchars', $elements));
}
}
}
}
}
}
// Make sure the charset is UTF-8 for Salesforce.
$merge_vars = array_map(array('GFSalesforce', '_convert_to_utf_8'), $merge_vars);
// Don't send merge_vars that are empty. It can cause problems with Salesforce strict typing. For example,
// if the form has a text field where a number should go, but that number isn't always required, when it's
// not supplied, we don't want to send <var></var> to Salesforce. It might choke because it expects a Double
// data type, not an empty string
$merge_vars = array_filter($merge_vars, array('GFSalesforce', '_remove_empty_fields'));
$account = new SObject();
$account->fields = $merge_vars;
// Object type
$account->type = $feed['meta']['contact_object_name'];
try {
$result = $api->create(array($account));
$api_exception = '';
} catch (Exception $e) {
$api_exception = "\r\n Message: " . $e->getMessage() . "\nFaultstring: " . $e->faultstring . "\nFile: " . $e->getFile() . "\nLine: " . $e->getLine() . "\nArgs: " . serialize($merge_vars) . "\nTrace: " . serialize($e->getTrace());
}
$debug = '';
if (self::is_debug()) {
$debug = '<pre>' . print_r(array('Form Entry Data' => $entry, 'Form Meta Data' => $form, 'Salesforce Feed Meta Data' => $feed, 'Salesforce Posted Merge Data' => $merge_vars, 'Posted Data ($_POST)' => $_POST, 'result' => $result[0], '$api' => $api, '$api_exception' => $api_exception), true) . '</pre>';
}
if (isset($result[0]) && !empty($result[0]->success)) {
if (self::is_debug()) {
echo '<h2>Success</h2>' . $debug;
}
gform_update_meta($entry['id'], 'salesforce_id', $result[0]->id);
self::add_note($entry["id"], sprintf(__('Successfully added to Salesforce with ID #%s . View entry at %s', 'gravity-forms-salesforce'), $result[0]->id, 'https://na9.salesforce.com/' . $result[0]->id));
return $result[0]->id;
} else {
$errors = $result[0]->errors[0];
if (self::is_debug()) {
echo '<h2>Error</h2>' . $debug;
echo '<h2>Errors</h2><pre>' . print_r($errors, true) . '</pre>';
}
if ($email = self::is_notify_on_error()) {
$message = sprintf(apply_filters('gravityforms_salesforce_notify_on_error_message', __("<h3>Error Adding To Salesforce</h3><p>There was an error when attempting to add <a href='%s'>Entry #%s</a> from the form \"%s\"</p>", 'gravity-forms-salesforce'), $errors, $entry, $form), admin_url('admin.php?page=gf_entries&view=entry&id=' . $entry['form_id'] . '&lid=' . $entry['id']), $entry['id'], $form['title']);
$headers = "Content-type: text/html; charset=" . get_option('blog_charset') . "\r\n";
wp_mail($email, __('Error adding to Salesforce', 'gravity-forms-salesforce'), $message, $headers);
}
self::add_note($entry["id"], sprintf(__('Errors when adding to Salesforce: %s', 'gravity-forms-salesforce'), $errors->message . $api_exception));
return false;
}
}
示例7: get_address
private function get_address($entry, $field_id)
{
$street_value = str_replace(' ', ' ', trim($entry[$field_id . '.1']));
$street2_value = str_replace(' ', ' ', trim($entry[$field_id . '.2']));
$city_value = str_replace(' ', ' ', trim($entry[$field_id . '.3']));
$state_value = str_replace(' ', ' ', trim($entry[$field_id . '.4']));
$zip_value = trim($entry[$field_id . '.5']);
$country_value = GFCommon::get_country_code(trim($entry[$field_id . '.6']));
$address = $street_value;
$address .= !empty($address) && !empty($street2_value) ? ' ' . $street2_value : $street2_value;
$address .= !empty($address) && (!empty($city_value) || !empty($state_value)) ? ' ' . $city_value : $city_value;
$address .= !empty($address) && !empty($city_value) && !empty($state_value) ? ' ' . $state_value : $state_value;
$address .= !empty($address) && !empty($zip_value) ? ' ' . $zip_value : $zip_value;
$address .= !empty($address) && !empty($country_value) ? ' ' . $country_value : $country_value;
return $address;
}
示例8: export_feed
public static function export_feed($entry, $form, $feed, $api)
{
#print_r($feed); die();
$double_optin = false;
// $feed["meta"]["double_optin"] ? true : false;
$send_welcome = false;
// $feed["meta"]["welcome_email"] ? true : false;
$email_field_id = $feed["meta"]["field_map"]["email_address"];
$email = $entry[$email_field_id];
$merge_vars = array('');
foreach ($feed["meta"]["field_map"] as $var_tag => $field_id) {
$field = RGFormsModel::get_field($form, $field_id);
if ($var_tag == 'address_full') {
$merge_vars[$var_tag] = self::get_address($entry, $field_id);
} else {
if ($var_tag == 'country') {
# echo $entry[$field_id]; die();
$merge_vars[$var_tag] = empty($entry[$field_id]) ? '' : GFCommon::get_country_code(trim($entry[$field_id]));
} else {
if ($var_tag != "email") {
if (!empty($entry[$field_id])) {
if ($field['type'] == 'textarea') {
$merge_vars[$var_tag] = '<![CDATA[' . $entry[$field_id] . ']]>';
} else {
$merge_vars[$var_tag] = $entry[$field_id];
}
} else {
foreach ($entry as $key => $value) {
if (floor($key) == floor($field_id) && !empty($value)) {
$merge_vars[$var_tag][] = $value;
}
}
}
}
}
}
}
if (apply_filters('gf_exacttarget_add_source', true) && isset($form['title'])) {
$merge_vars['source_form'] = $form['title'];
}
if ((empty($api->addtype) || $api->addtype == 'api') && empty($api->subscriberkey)) {
$lists = explode(',', $feed["meta"]["contact_list_id"]);
foreach ($lists as $list) {
$api->AddMembership($list, $email, $merge_vars);
}
} else {
$api->listSubscribe($feed["meta"]["contact_list_id"], $email, $merge_vars);
}
}
示例9: customer_query_string
protected function customer_query_string($feed, $lead)
{
$fields = '';
foreach ($this->get_customer_fields() as $field) {
$field_id = $feed['meta'][$field['meta_name']];
$value = rgar($lead, $field_id);
if ($field['name'] == 'country') {
$value = GFCommon::get_country_code($value);
} else {
if ($field['name'] == 'state') {
$value = GFCommon::get_us_state_code($value);
}
}
if (!empty($value)) {
$fields .= "&{$field['name']}=" . urlencode($value);
}
}
return $fields;
}
示例10: prepare_credit_card_transaction
/**
* Prepare the transaction arguments.
*
* @param array $feed The feed object currently being processed.
* @param array $submission_data The customer and transaction data.
* @param array $form The form object currently being processed.
* @param array $entry The entry object currently being processed.
*
* @return array
*/
public function prepare_credit_card_transaction($feed, $submission_data, $form, $entry)
{
$feed_name = rgar($feed['meta'], 'feedName');
$this->log_debug(__METHOD__ . "(): Preparing transaction arguments based on feed #{$feed['id']} - {$feed_name}.");
$this->log_debug(__METHOD__ . '(): $submission_data line_items => ' . print_r($submission_data['line_items'], 1));
// Billing Information
$card_number = $submission_data['card_number'];
$expiration_date = str_pad($submission_data['card_expiration_date'][0], 2, '0', STR_PAD_LEFT) . substr($submission_data['card_expiration_date'][1], -2);
// ?? correct format ??
$country = $submission_data['country'];
$country = GFCommon::get_country_code($country);
$args = array();
$args['ACCT'] = $card_number;
$args['EXPDATE'] = $expiration_date;
$args['CVV2'] = $submission_data['card_security_code'];
$args['STREET'] = $submission_data['address'];
$args['BILLTOSTREET2'] = $submission_data['address2'];
$args['CITY'] = $submission_data['city'];
$args['STATE'] = $submission_data['state'];
$args['ZIP'] = $submission_data['zip'];
$args['BILLTOCOUNTRY'] = $country == 'UK' ? 'GB' : $country;
$args['CURRENCY'] = GFCommon::get_currency();
// Customer Information
$args['FIRSTNAME'] = $submission_data['firstName'];
$args['LASTNAME'] = $submission_data['lastName'];
$args['EMAIL'] = $submission_data['email'];
// Product Information
$i = 0;
$args['DESC'] = '';
foreach ($submission_data['line_items'] as $line_item) {
if ($feed['meta']['transactionType'] == 'product') {
$args["L_NAME{$i}"] = $line_item['name'];
$args["L_DESC{$i}"] = $line_item['description'];
$args["L_AMT{$i}"] = $line_item['unit_price'];
$args["L_NUMBER{$i}"] = $i + 1;
$args["L_QTY{$i}"] = $line_item['quantity'];
} else {
$args['DESC'] .= $i > 1 ? ', ' . $line_item['name'] : $line_item['name'];
// ?? TO DO figure out why there is warning that desc is undefined
}
$i++;
}
$args['AMT'] = $submission_data['payment_amount'];
$args['TENDER'] = 'C';
return $args;
}
示例11: processSinglePayment
/**
* process regular one-off payment
* @param array $data an array with elements is_valid (boolean) and form (array of form elements)
* @param GFEwayFormData $formData pre-parsed data from $data
* @return array
*/
protected function processSinglePayment($data, $formData)
{
try {
if ($this->options['useStored']) {
$eway = new GFEwayStoredPayment($this->getCustomerID(), !$this->options['useTest']);
} else {
$eway = new GFEwayPayment($this->getCustomerID(), !$this->options['useTest']);
}
$eway->sslVerifyPeer = $this->options['sslVerifyPeer'];
$eway->invoiceDescription = get_bloginfo('name') . " -- {$data['form']['title']}";
$eway->invoiceReference = $data['form']['id'];
if (empty($formData->firstName) && empty($formData->lastName)) {
$eway->lastName = $formData->ccName;
// pick up card holder's name for last name
} else {
$eway->firstName = $formData->firstName;
$eway->lastName = $formData->lastName;
}
$eway->cardHoldersName = $formData->ccName;
$eway->cardNumber = $formData->ccNumber;
$eway->cardExpiryMonth = $formData->ccExpMonth;
$eway->cardExpiryYear = $formData->ccExpYear;
$eway->emailAddress = $formData->email;
$eway->address = $formData->address;
$eway->postcode = $formData->postcode;
$eway->cardVerificationNumber = $formData->ccCVN;
// if Beagle is enabled, get the country code
if ($this->options['useBeagle']) {
$eway->customerCountryCode = GFCommon::get_country_code($formData->address_country);
}
// allow plugins/themes to modify invoice description and reference, and set option fields
$eway->invoiceDescription = apply_filters('gfeway_invoice_desc', $eway->invoiceDescription, $data['form']);
$eway->invoiceReference = apply_filters('gfeway_invoice_ref', $eway->invoiceReference, $data['form']);
$eway->transactionNumber = apply_filters('gfeway_invoice_trans_number', $eway->transactionNumber, $data['form']);
$eway->option1 = apply_filters('gfeway_invoice_option1', '', $data['form']);
$eway->option2 = apply_filters('gfeway_invoice_option2', '', $data['form']);
$eway->option3 = apply_filters('gfeway_invoice_option3', '', $data['form']);
// if live, pass through amount exactly, but if using test site, round up to whole dollars or eWAY will fail
if ($this->options['useTest'] && $this->options['roundTestAmounts']) {
$eway->amount = ceil($formData->total);
if ($eway->amount != $formData->total) {
self::log_debug(sprintf('%s: amount rounded up from %s to %s to pass sandbox gateway', __FUNCTION__, number_format($formData->total, 2), number_format($eway->amount, 2)));
}
} else {
$eway->amount = $formData->total;
}
self::log_debug(sprintf('%s: %s gateway, invoice ref: %s, transaction: %s, amount: %s, cc: %s', __FUNCTION__, $eway->isLiveSite ? 'live' : 'test', $eway->invoiceReference, $eway->transactionNumber, $eway->amount, $eway->cardNumber));
// record basic transaction data, for updating the entry with later
$this->txResult = array('payment_gateway' => 'gfeway', 'gfeway_unique_id' => GFFormsModel::get_form_unique_id($data['form']['id']));
$response = $eway->processPayment();
if ($response->status) {
// transaction was successful, so record details and continue
$this->txResult['payment_status'] = $this->options['useStored'] ? 'Pending' : 'Approved';
$this->txResult['payment_date'] = date('Y-m-d H:i:s');
$this->txResult['payment_amount'] = $response->amount;
$this->txResult['transaction_id'] = $response->transactionNumber;
$this->txResult['transaction_type'] = 1;
$this->txResult['authcode'] = $response->authCode;
$this->txResult['beagle_score'] = $response->beagleScore;
self::log_debug(sprintf('%s: success, date = %s, id = %s, status = %s, amount = %s, authcode = %s, Beagle = %s', __FUNCTION__, $this->txResult['payment_date'], $response->transactionNumber, $this->txResult['payment_status'], $response->amount, $response->authCode, $response->beagleScore));
} else {
$data['is_valid'] = false;
$formData->ccField['failed_validation'] = true;
$formData->ccField['validation_message'] = nl2br($this->getErrMsg(GFEWAY_ERROR_EWAY_FAIL) . ":\n{$response->error}");
$this->txResult['payment_status'] = 'Failed';
$this->txResult['authcode'] = '';
// empty bank authcode, for conditional logic
self::log_debug(sprintf('%s: failed; %s', __FUNCTION__, $response->error));
}
} catch (GFEwayException $e) {
$data['is_valid'] = false;
$formData->ccField['failed_validation'] = true;
$formData->ccField['validation_message'] = nl2br($this->getErrMsg(GFEWAY_ERROR_EWAY_FAIL) . ":\n{$e->getMessage()}");
$this->txResult['payment_status'] = 'Failed';
$this->txResult['authcode'] = '';
// empty bank authcode, for conditional logic
self::log_error(__METHOD__ . ": " . $e->getMessage());
}
return $data;
}
示例12: paypalpro_validation
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"]);
//.........這裏部分代碼省略.........