• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
Easy Digital Downloads a2z

Easy Digital Downloads a2z

Easy Digital Downloads a2z

  • Home
  • Plugins
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / edd_process_paypal_web_accept_and_cart() – Process web accept (one time) payment IPNs

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 );

  }
 
[1] [2] [3] Next »

 View on GitHub View on Trac

Published: 26th November 2019 | Last updated: 13th March 2021

Primary Sidebar

Information

Function name: edd_process_paypal_web_accept_and_cart
Plugin ref: Easy Digital Downloads
Version: 2.11.6
Sourcefile: includes/gateways/paypal-standard.php
File ref: includes/gateways/paypal-standard.php
Deprecated?: No
API Letters: A,E,P,W

Footer

Easy Digital Downloads a2z
Easy Digital Downloads a2z
Easy Digital Downloads a2z
WordPress 5.9.3
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  edd.wp-a2z.org
© Copyright Easy Digital Downloads a2z 2014-2022. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites