HEX
Server: Apache/2
System: Linux bq-e705.pointdnshere.com 4.18.0-513.11.1.el8_9.x86_64 #1 SMP Wed Jan 17 02:00:40 EST 2024 x86_64
User: wellmix (1103)
PHP: 7.4.33
Disabled: NONE
Upload Files
File: /home/wellmix/public_html/wp-content/plugins/pymntpl-paypal-woocommerce/src/Tokens/PayPalToken.php
<?php

namespace PaymentPlugins\WooCommerce\PPCP\Tokens;

use PaymentPlugins\PayPalSDK\Payer;
use PaymentPlugins\PayPalSDK\PayerInfo;

class PayPalToken extends AbstractToken {

	protected $type = 'PPCP';

	public function get_payment_method_formats() {
		return apply_filters( 'wc_ppcp_payment_method_formats', [
			'name'       => [
				'format'  => __( 'PayPal', 'pymntpl-paypal-woocommerce' ),
				'example' => __( 'PayPal', 'pymntpl-paypal-woocommerce' ),
				'label'   => __( 'PayPal', 'pymntpl-paypal-woocommerce' )
			],
			'name_email' => [
				'format'  => __( 'PayPal', 'pymntpl-paypal-woocommerce' ) . ' - {email}',
				'example' => __( 'PayPal - john@paypal.com', 'pymntpl-paypal-woocommerce' ),
				'label'   => __( 'Name plus email', 'pymntpl-paypal-woocommerce' )
			]
		], $this );
	}

	protected function get_default_format() {
		return 'name_email';
	}

	/**
	 * @param Payer|PayerInfo $payer
	 *
	 * @return mixed|void
	 */
	public function initialize_from_payer( $payer ) {
		if ( $payer instanceof Payer ) {
			$this->set_first_name( $payer->name->given_name );
			$this->set_last_name( $payer->name->surname );
			$this->set_email( $payer->email_address );
			$this->set_payer_id( $payer->payer_id );
		} elseif ( $payer instanceof PayerInfo ) {
			$this->set_first_name( $payer->first_name );
			$this->set_last_name( $payer->last_name );
			$this->set_email( $payer->email );
			$this->set_payer_id( $payer->payer_id );
		}
	}
}