Making WordPress.org

Ticket #1074: #1074.2.patch

File #1074.2.patch, 2.9 KB (added by saurabhshukla, 9 years ago)
  • addons/payment-paypal.php

    diff --git a/addons/payment-paypal.php b/addons/payment-paypal.php
    index ee99700..7a2f50c 100644
    a b  
    726726        }
    727727
    728728        /**
     729         * Checks if a transaction is refundable
     730         *
     731         * @global type $camptix
     732         * @param type $payment_token
     733         * @return boolean
     734         */
     735        function transaction_is_refundable( $payment_token ){
     736                /** @var $camptix CampTix_Plugin */
     737                global $camptix;
     738
     739                $refund_expiry = 60; // no. of days
     740
     741                if ( empty( $refund_expiry ) )
     742                        return true;
     743
     744                $txn_details = $camptix->get_post_meta_from_payment_token( $payment_token, 'tix_transaction_details' );
     745
     746                // more than 60 days since transaction
     747                if( strtotime( $txn_details['raw']['TIMESTAMP'] + $refund_expiry * DAY_IN_SECONDS ) < time() )
     748                        return new WP_Error('refund-expired', sprintf( __( 'PayPal error: PayPal only allows refund within %d days.', 'camptix' ), $refund_expiry ) );
     749
     750                return true; // return true by default
     751
     752        }
     753
     754        /**
    729755         * Submits a single, user-initiated refund request to PayPal and returns the result
    730756         *
    731757         * @param string $payment_token
     
    733759         * @return int One of the CampTix_Plugin::PAYMENT_STATUS_{status} constants
    734760         */
    735761        function payment_refund( $payment_token ) {
     762
     763                // check if this is within PayPal's 60 day refund period
     764                $is_refundable = $this->transaction_is_refundable( $payment_token );
     765
     766                if( is_wp_error( $is_refundable ) )
     767                        return $is_refundable;
     768
    736769                /** @var $camptix CampTix_Plugin */
    737770                global $camptix;
    738771
  • camptix.php

    diff --git a/camptix.php b/camptix.php
    index 62a30fa..4bbb0eb 100644
    a b  
    58525852
    58535853                                // Attempt to process the refund transaction
    58545854                                $result = $payment_method_obj->payment_refund( $transaction['payment_token'] );
    5855                                 $this->log( 'Individual refund request result.', $attendee->ID, $result, 'refund' );
    5856                                 if ( CampTix_Plugin::PAYMENT_STATUS_REFUNDED == $result ) {
     5855
     5856                                if ( CampTix_Plugin::PAYMENT_STATUS_REFUNDED === $result ) {
    58575857                                        foreach ( $attendees as $attendee ) {
    58585858                                                update_post_meta( $attendee->ID, 'tix_refund_reason', $reason );
    58595859                                                $this->log( 'Refund reason attached with data.', $attendee->ID, $reason, 'refund' );
    58605860                                        }
    58615861
     5862                                        $this->log( 'Individual refund request result.', $attendee->ID, $result, 'refund' );
    58625863                                        $this->info( __( 'Your tickets have been successfully refunded.', 'camptix' ) );
     5864
    58635865                                        return $this->form_refund_success();
     5866
     5867                                } elseif ( is_wp_error( $result )){
     5868
     5869                                        $err_msg = $result->get_error_message();
     5870                                        $this->log( 'Individual refund request result.', $attendee->ID, $err_msg, 'refund' );
     5871                                        $this->error( $err_msg );
    58645872                                } else {
     5873                                        $this->log( 'Individual refund request result.', $attendee->ID, $result, 'refund' );
    58655874                                        $this->error( __( 'Can not refund the transaction at this time. Please try again later.', 'camptix' ) );
    58665875                                }
     5876
    58675877                        }
    58685878                }
    58695879