diff --git a/addons/payment-paypal.php b/addons/payment-paypal.php
index ee99700..7a2f50c 100644
a
|
b
|
|
726 | 726 | } |
727 | 727 | |
728 | 728 | /** |
| 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 | /** |
729 | 755 | * Submits a single, user-initiated refund request to PayPal and returns the result |
730 | 756 | * |
731 | 757 | * @param string $payment_token |
… |
… |
|
733 | 759 | * @return int One of the CampTix_Plugin::PAYMENT_STATUS_{status} constants |
734 | 760 | */ |
735 | 761 | 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 | |
736 | 769 | /** @var $camptix CampTix_Plugin */ |
737 | 770 | global $camptix; |
738 | 771 | |
diff --git a/camptix.php b/camptix.php
index 62a30fa..4bbb0eb 100644
a
|
b
|
|
5852 | 5852 | |
5853 | 5853 | // Attempt to process the refund transaction |
5854 | 5854 | $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 ) { |
5857 | 5857 | foreach ( $attendees as $attendee ) { |
5858 | 5858 | update_post_meta( $attendee->ID, 'tix_refund_reason', $reason ); |
5859 | 5859 | $this->log( 'Refund reason attached with data.', $attendee->ID, $reason, 'refund' ); |
5860 | 5860 | } |
5861 | 5861 | |
| 5862 | $this->log( 'Individual refund request result.', $attendee->ID, $result, 'refund' ); |
5862 | 5863 | $this->info( __( 'Your tickets have been successfully refunded.', 'camptix' ) ); |
| 5864 | |
5863 | 5865 | 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 ); |
5864 | 5872 | } else { |
| 5873 | $this->log( 'Individual refund request result.', $attendee->ID, $result, 'refund' ); |
5865 | 5874 | $this->error( __( 'Can not refund the transaction at this time. Please try again later.', 'camptix' ) ); |
5866 | 5875 | } |
| 5876 | |
5867 | 5877 | } |
5868 | 5878 | } |
5869 | 5879 | |