php [专业网站] - 条纹付款日志

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php [专业网站] - 条纹付款日志相关的知识,希望对你有一定的参考价值。

<?php
/**
* Plugin Name: [Pro Sites] - Stripe Payment Logs
* Plugin URI: https://premium.wpmudev.org/
* Description: Logs Stripe Payments in 3 log files both located in mu-plugins dir. One with specific info about payment, one that contains the raw request, and one that contains the stripe subscription object
* Author: Panos Lyrakis @ WPMUDEV
* Author URI: https://premium.wpmudev.org/
* License: GPLv2 or later
*/
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( ! class_exists( 'WPMUDEV_PS_Stripe_Loger' ) ) {
    
    class WPMUDEV_PS_Stripe_Loger {
        private static $_instance = null;

        public static function get_instance() {
            if( is_null( self::$_instance ) ){
                self::$_instance = new WPMUDEV_PS_Stripe_Loger();
            }
            return self::$_instance;
            
        }

        private function __construct() {

        	add_action( 'wp_ajax_nopriv_psts_stripe_webhook', array( &$this, 'payment_received' ) );
            add_action( 'wp_ajax_psts_stripe_webhook', array( &$this, 'payment_received' ) );

        }

        public function payment_received() {

        	$body = @file_get_contents( 'php://input' );
			$event_json = json_decode( $body );
            $now = date( 'd M Y H:i:s' );
            $log_content = '';
            $customer_id = '';

            if ( ! empty( $event_json->data->object->object ) && 'customer' == $event_json->data->object->object ) {
                $customer_id = $event_json->data->object->id;
            } elseif ( ! empty( $event_json->data->object->customer ) ) {
                $customer_id = $event_json->data->object->customer;
            }

            $subscription = ProSites_Gateway_Stripe::get_subscription( $event_json );

            if ( isset( $subscription->blog_id ) && ! empty( $subscription->blog_id ) ) {
                $blog_id = (int) $subscription->blog_id;
            }

            if ( '' == $blog_id && ! empty( $subscription ) && ! isset( $subscription->metadata->blog_id ) && ! isset( $subscription->blog_id ) ) {
                $blog_id = ProSites_Gateway_Stripe::get_blog_id( $customer_id );
            }

            $event_type = $event_json->type;
            $plan           = ! empty( $subscription->plan ) ? $subscription->plan->id : null;
            $is_trial       = ! empty( $subscription ) ? $subscription->is_trial : null;
            $plan_end       = ! empty( $subscription ) ? date( 'd-m-Y H:i:s', $subscription->period_end ) : null;
            $plan_amount    = ! empty( $subscription ) ? $subscription->plan_amount : null;
            $amount         = ! empty( $subscription ) ? $subscription->subscription_amount : null;
            $invoice_items  = ! empty( $subscription ) ? $subscription->invoice_items : null;

            $log_content = "\n\n\n=======================\n\n\n{$now}\n\n";
            $log_content .= "blog_id : {$blog_id}\n";
            $log_content .= "customer_id : {$customer_id}\n\n";
            $log_content .= "event_type : {$event_type}\n\n";

            if ( ! is_null( $plan ) ) {
                $log_content .= "plan : {$plan}\n";
            }

            if( $is_trial ){
                $log_content .= "trial : YES\n";
            }
            else {
                $log_content .= "trial : NO\n";
            }

            if ( ! is_null( $plan_end ) ) {
                $log_content .= "plan_end : {$plan_end}\n";
            }

            if ( ! is_null( $plan_amount ) ) {
                $log_content .= "plan_amount : {$plan_amount}\n";
            }

            if ( ! is_null( $invoice_items ) ) {
                $log_content .= "invoice_items : {$invoice_items}\n";
            }

            self::log( $subscription, 'ps-stripe-subscriptions.log' );
            self::log( $body, 'ps-stripe-raw.log' );
            self::log( $log_content );

        }


        public static function log( $data, $log_file = null, $log_file_path = null ) {

        	$data = is_array( $data ) || is_object( $data ) ? print_r( $data, true ) : $data;
        	$log_file = is_null( $log_file ) ? 'ps-stripe.log' : $log_file;
        	$log_file_path = is_null( $log_file_path ) ? WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'mu-plugins' : $log_file_path;
        	$log_file = $log_file_path . DIRECTORY_SEPARATOR . $log_file;
        	$date = date( 'd-m-Y H:i:s' );

        	error_log( "\n\n[ {$date} ] \n{$data}", 3, $log_file );

        }

    }

    add_action( 'plugins_loaded', function(){
        $GLOBALS['WPMUDEV_PS_Stripe_Loger'] = WPMUDEV_PS_Stripe_Loger::get_instance();
    }, 10 );

}

以上是关于php [专业网站] - 条纹付款日志的主要内容,如果未能解决你的问题,请参考以下文章

Apple Pay - “付款未完成” - 使用 Stripe

使用nodeJS条纹创建付款意图

C#:在条纹中设置默认付款方式

条纹自定义付款表单:ActiveRecord::RecordNotFound

条纹 Firebase 功能以设置默认付款

条纹结帐键盘隐藏付款按钮