You appear to be a bot. Output may be restricted
Description
Process web accept (one time) payment IPNs
Usage
$void = edd_process_paypal_web_accept_and_cart( $data, $payment_id );
Parameters
- $data
- ( array ) required – IPN Data
- $payment_id
- ( mixed ) required –
Returns
void
Source
File name: easy-digital-downloads/includes/gateways/paypal-standard.php
Lines:
1 to 100 of 221
function edd_process_paypal_web_accept_and_cart( $data, $payment_id ) { /** * PayPal Web Accept Data * * Allows filtering the Web Accept data that PayPal passes back in via IPN with PayPal Standard * * @since 2.8.13 * * @param array $data The PayPal Web Accept Data * @param int $payment_id The Payment ID associated with this IPN request */ $data = apply_filters( 'edd_paypal_web_accept_and_cart_data', $data, $payment_id ); if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) { return; } if( empty( $payment_id ) ) { return; } $payment = new EDD_Payment( $payment_id ); // Collect payment details $purchase_key = isset( $data['invoice'] ) ? $data['invoice'] : false; if ( ! $purchase_key && ! empty( $data['item_number'] ) ) { $purchase_key = $data['item_number']; } $paypal_amount = $data['mc_gross']; $payment_status = strtolower( $data['payment_status'] ); $currency_code = strtolower( $data['mc_currency'] ); $business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] ); if ( $payment->gateway != 'paypal' ) { return; // this isn't a PayPal standard IPN } // Verify payment recipient if ( strcasecmp( $business_email, trim( edd_get_option( 'paypal_email', false ) ) ) != 0 ) { edd_record_gateway_error( __( 'IPN Error', 'easy-digital-downloads' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'easy-digital-downloads' ), json_encode( $data ) ), $payment_id ); edd_debug_log( 'Invalid business email in IPN response. IPN data: ' . print_r( $data, true ) ); edd_update_payment_status( $payment_id, 'failed' ); edd_insert_payment_note( $payment_id, __( 'Payment failed due to invalid PayPal business email.', 'easy-digital-downloads' ) ); return; } // Verify payment currency if ( $currency_code != strtolower( $payment->currency ) ) { edd_record_gateway_error( __( 'IPN Error', 'easy-digital-downloads' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'easy-digital-downloads' ), json_encode( $data ) ), $payment_id ); edd_debug_log( 'Invalid currency in IPN response. IPN data: ' . print_r( $data, true ) ); edd_update_payment_status( $payment_id, 'failed' ); edd_insert_payment_note( $payment_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'easy-digital-downloads' ) ); return; } if ( empty( $payment->email ) ) { // This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal // Setup and store the customers's details $address = array(); $address['line1'] = ! empty( $data['address_street'] ) ? sanitize_text_field( $data['address_street'] ) : false; $address['city'] = ! empty( $data['address_city'] ) ? sanitize_text_field( $data['address_city'] ) : false; $address['state'] = ! empty( $data['address_state'] ) ? sanitize_text_field( $data['address_state'] ) : false; $address['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false; $address['zip'] = ! empty( $data['address_zip'] ) ? sanitize_text_field( $data['address_zip'] ) : false; $payment->email = sanitize_text_field( $data['payer_email'] ); $payment->first_name = sanitize_text_field( $data['first_name'] ); $payment->last_name = sanitize_text_field( $data['last_name'] ); $payment->address = $address; if( empty( $payment->customer_id ) ) { $customer = new EDD_Customer( $payment->email ); if( ! $customer || $customer->id < 1 ) { $customer->create( array( 'email' => $payment->email, 'name' => $payment->first_name . ' ' . $payment->last_name, 'user_id' => $payment->user_id ) ); } $payment->customer_id = $customer->id; } $payment->save(); } if( empty( $customer ) ) { $customer = new EDD_Customer( $payment->customer_id ); }