forked from LiveCarta/LiveCartaWP
Changed source root directory
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
class PostmanElasticEmail extends PostmanServiceRequest {
|
||||
|
||||
/**
|
||||
* Success Code
|
||||
*
|
||||
* @since 2.6.0
|
||||
* @version 1.0
|
||||
*/
|
||||
private $email_sent_code = 200;
|
||||
|
||||
/**
|
||||
* API Key
|
||||
*
|
||||
* @since 2.6.0
|
||||
* @version 1.0
|
||||
*/
|
||||
private $api_key = '';
|
||||
|
||||
/**
|
||||
* Base URL
|
||||
*
|
||||
* @since 2.6.0
|
||||
* @version 1.0
|
||||
*/
|
||||
private $base_url = 'https://api.elasticemail.com/v4/emails';
|
||||
|
||||
/**
|
||||
* constructor ElasticEmail
|
||||
*
|
||||
* @param $api_key
|
||||
* @since 2.6.0
|
||||
* @version 1.0
|
||||
*/
|
||||
public function __construct( $api_key ) {
|
||||
|
||||
$this->api_key = $api_key;
|
||||
|
||||
parent::__construct( $this->base_url );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares Header for Request
|
||||
*
|
||||
* @since 2.6.0
|
||||
* @version 1.0
|
||||
*/
|
||||
private function get_headers() {
|
||||
|
||||
return array(
|
||||
'X-ElasticEmail-ApiKey' => $this->api_key
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends Email using ElasticEmail transactional end point
|
||||
*
|
||||
* @param $api_key
|
||||
* @since 2.6.0
|
||||
* @version 1.0
|
||||
*/
|
||||
public function send( $content ) {
|
||||
|
||||
$content = json_encode( $content );
|
||||
|
||||
return $this->request(
|
||||
'POST',
|
||||
'/transactional',
|
||||
$this->get_headers(),
|
||||
$content,
|
||||
$this->email_sent_code
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
class PostmanEmailit extends PostmanServiceRequest {
|
||||
/**
|
||||
* Success Code
|
||||
*/
|
||||
private $email_sent_code = 200;
|
||||
|
||||
/**
|
||||
* API Key
|
||||
*/
|
||||
private $api_key = '';
|
||||
|
||||
/**
|
||||
* Base URL (endpoint)
|
||||
*/
|
||||
private $base_url = 'https://api.emailit.com';
|
||||
|
||||
/**
|
||||
* Options instance
|
||||
* @var PostmanOptions
|
||||
*/
|
||||
private $options;
|
||||
|
||||
/**
|
||||
* constructor PostmanEmailit
|
||||
* @param $api_key
|
||||
* @param $endpoint
|
||||
*/
|
||||
public function __construct( $api_key ) {
|
||||
$this->api_key = $api_key;
|
||||
parent::__construct( $this->base_url );
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares Header for Request
|
||||
*/
|
||||
private function get_headers() {
|
||||
return array(
|
||||
'Content-Type' => 'application/json',
|
||||
'Authorization' => 'Bearer ' . $this->api_key
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends Email using Emailit API
|
||||
* @param $content
|
||||
* @return mixed
|
||||
*/
|
||||
public function send( $content ) {
|
||||
$content = json_encode( $content );
|
||||
return $this->request(
|
||||
'POST',
|
||||
'/v1/emails',
|
||||
$this->get_headers(),
|
||||
$content,
|
||||
$this->email_sent_code
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
<?php
|
||||
|
||||
class PostmanMailGun extends PostmanServiceRequest {
|
||||
|
||||
/**
|
||||
* Success Code
|
||||
*
|
||||
* @since 2.2
|
||||
* @version 1.0
|
||||
*/
|
||||
private $email_sent_code = 200;
|
||||
|
||||
/**
|
||||
* API Key
|
||||
*
|
||||
* @since 2.2
|
||||
* @version 1.0
|
||||
*/
|
||||
private $api_key = '';
|
||||
|
||||
/**
|
||||
* Base URL US Region
|
||||
*
|
||||
* @since 2.2
|
||||
* @version 1.0
|
||||
*/
|
||||
private $base_url_us = 'https://api.mailgun.net/v3/';
|
||||
/**
|
||||
* Base URL EU Region
|
||||
*
|
||||
* @since 2.2
|
||||
* @version 1.0
|
||||
*/
|
||||
private $base_url_eu = 'https://api.eu.mailgun.net/v3/';
|
||||
|
||||
/**
|
||||
* Content
|
||||
*
|
||||
* @since 2.2
|
||||
* @version 1.0
|
||||
*/
|
||||
private $content = array();
|
||||
|
||||
/**
|
||||
* constructor PostmanMailGun
|
||||
*
|
||||
* @param $api_key
|
||||
* @since 2.2
|
||||
* @version 1.0
|
||||
*/
|
||||
public function __construct( $api_key, $region, $domain ) {
|
||||
$base_url = ! is_null( $region ) ? $this->base_url_eu : $this->base_url_us;
|
||||
$base_url .= $domain;
|
||||
|
||||
$this->api_key = $api_key;
|
||||
parent::__construct( $base_url );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares Header for Request
|
||||
*
|
||||
* @since 2.2
|
||||
* @version 1.0
|
||||
*/
|
||||
private function get_headers() {
|
||||
|
||||
$headers = array();
|
||||
$headers['Authorization'] = 'Basic ' . base64_encode('api:' . $this->api_key);
|
||||
|
||||
|
||||
if( isset( $this->content['attachment'] ) ) {
|
||||
|
||||
//Remove attachment from content, to manage it separately
|
||||
$attachments = $this->content['attachment'];
|
||||
unset( $this->content['attachment'] );
|
||||
|
||||
//Let's create the boundary string. It must be unique
|
||||
//so we use the MD5 algorithm to generate a random hash
|
||||
$boundary = md5( date( 'r', time() ) );
|
||||
$headers['Content-Type'] = 'multipart/form-data; boundary=' . $boundary;
|
||||
$payload = '';
|
||||
|
||||
foreach( $this->content as $key => $value ) {
|
||||
|
||||
if ( is_array( $value ) ) {
|
||||
|
||||
foreach ( $value as $child_value ) {
|
||||
|
||||
$payload .= '--' . $boundary;
|
||||
$payload .= "\r\n";
|
||||
$payload .= 'Content-Disposition: form-data; name="' . $key . "\"\r\n\r\n";
|
||||
$payload .= $child_value;
|
||||
$payload .= "\r\n";
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
$payload .= '--' . $boundary;
|
||||
$payload .= "\r\n";
|
||||
$payload .= 'Content-Disposition: form-data; name="' . $key . '"' . "\r\n\r\n";
|
||||
$payload .= $value;
|
||||
$payload .= "\r\n";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Add attachments
|
||||
foreach( $attachments as $key => $attachment ) {
|
||||
|
||||
$payload .= '--' . $boundary;
|
||||
$payload .= "\r\n";
|
||||
$payload .= 'Content-Disposition: form-data; name="attachment[' . $key . ']"; filename="' . $attachment['filePath'] . '"' . "\r\n\r\n";
|
||||
$payload .= file_get_contents( $attachment['filePath'] );
|
||||
$payload .= "\r\n";
|
||||
|
||||
}
|
||||
|
||||
$payload .= '--' . $boundary . '--';
|
||||
|
||||
//Overwrite body with payload
|
||||
$this->content = $payload;
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
$headers['Content-Type'] = 'application/x-www-form-urlencoded';
|
||||
|
||||
}
|
||||
|
||||
return $headers;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends Email using MailGun email end point
|
||||
*
|
||||
* @param $api_key
|
||||
* @since 2.2
|
||||
* @version 1.0
|
||||
*/
|
||||
public function send( $content ) {
|
||||
|
||||
$this->content = $content;
|
||||
|
||||
return $this->request(
|
||||
'POST',
|
||||
'/messages',
|
||||
$this->get_headers(),
|
||||
$this->content,
|
||||
$this->email_sent_code
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
class PostmanMailerSend extends PostmanServiceRequest {
|
||||
|
||||
/**
|
||||
* Success Code
|
||||
*
|
||||
* @since 3.3.0
|
||||
* @version 1.0
|
||||
*/
|
||||
private $email_sent_code = 202;
|
||||
|
||||
/**
|
||||
* API Key
|
||||
*
|
||||
* @since 3.3.0
|
||||
* @version 1.0
|
||||
*/
|
||||
private $api_key = '';
|
||||
|
||||
/**
|
||||
* Base URL
|
||||
*
|
||||
* @since 3.3.0
|
||||
* @version 1.0
|
||||
*/
|
||||
private $base_url = 'https://api.mailersend.com/v1/';
|
||||
|
||||
/**
|
||||
* Options instance
|
||||
*
|
||||
* @var PostmanOptions
|
||||
*/
|
||||
private $options;
|
||||
|
||||
/**
|
||||
* constructor PostmanMailerSend
|
||||
*
|
||||
* @param $api_key
|
||||
* @since 3.3.0
|
||||
* @version 1.0
|
||||
*/
|
||||
public function __construct( $api_key ) {
|
||||
|
||||
$this->api_key = $api_key;
|
||||
$this->options = PostmanOptions::getInstance();
|
||||
parent::__construct( $this->base_url );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares Header for Request
|
||||
*
|
||||
* @since 3.3.0
|
||||
* @version 1.0
|
||||
*/
|
||||
private function get_headers() {
|
||||
|
||||
return array(
|
||||
'Content-Type' => 'application/json',
|
||||
'Authorization' => 'Bearer ' . $this->api_key
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends Email using MailerSend email end point
|
||||
*
|
||||
* @param $api_key
|
||||
* @since 3.3.0
|
||||
* @version 1.0
|
||||
*/
|
||||
public function send( $content ) {
|
||||
|
||||
$content = json_encode( $content );
|
||||
|
||||
return $this->request(
|
||||
'POST',
|
||||
'email',
|
||||
$this->get_headers(),
|
||||
$content,
|
||||
$this->email_sent_code
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
class PostmanMaileroo extends PostmanServiceRequest {
|
||||
/**
|
||||
* Success Code
|
||||
*/
|
||||
private $email_sent_code = 200;
|
||||
|
||||
/**
|
||||
* API Key
|
||||
*/
|
||||
private $api_key = '';
|
||||
|
||||
/**
|
||||
* Base URL (endpoint)
|
||||
*/
|
||||
private $base_url = 'https://smtp.maileroo.com/';
|
||||
|
||||
/**
|
||||
* Options instance
|
||||
* @var PostmanOptions
|
||||
*/
|
||||
private $options;
|
||||
|
||||
/**
|
||||
* constructor PostmanMaileroo
|
||||
* @param $api_key
|
||||
* @param $endpoint
|
||||
*/
|
||||
public function __construct( $api_key ) {
|
||||
$this->api_key = $api_key;
|
||||
parent::__construct( $this->base_url );
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares Header for Request
|
||||
*/
|
||||
private function get_headers() {
|
||||
return array(
|
||||
'Content-Type' => 'application/json',
|
||||
'Authorization' => 'Bearer ' . $this->api_key
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends Email using Maileroo API
|
||||
* @param $content
|
||||
* @return mixed
|
||||
*/
|
||||
public function send( $content ) {
|
||||
$content = json_encode( $content );
|
||||
return $this->request(
|
||||
'POST',
|
||||
'api/v2/emails',
|
||||
$this->get_headers(),
|
||||
$content,
|
||||
$this->email_sent_code
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
class PostmanMailjet extends PostmanServiceRequest {
|
||||
|
||||
/**
|
||||
* Success Code
|
||||
*
|
||||
* @since 2.7
|
||||
* @version 1.0
|
||||
*/
|
||||
private $email_sent_code = 200;
|
||||
|
||||
/**
|
||||
* API Key
|
||||
*
|
||||
* @since 2.7
|
||||
* @version 1.0
|
||||
*/
|
||||
private $api_key = '';
|
||||
private $secret_key = '';
|
||||
private $auth = false;
|
||||
|
||||
|
||||
/**
|
||||
* Base URL
|
||||
*
|
||||
* @since 2.7
|
||||
* @version 1.0
|
||||
*/
|
||||
private $base_url = 'https://api.mailjet.com/v3';
|
||||
|
||||
/**
|
||||
* constructor PostmanMailjet
|
||||
*
|
||||
* @param $api_key
|
||||
* @since 2.7
|
||||
* @version 1.0
|
||||
*/
|
||||
public function __construct( $api_key, $secret_key ) {
|
||||
|
||||
$this->api_key = $api_key;
|
||||
$this->secret_key =$secret_key;
|
||||
|
||||
parent::__construct( $this->base_url );
|
||||
|
||||
}
|
||||
|
||||
private function get_auth(){
|
||||
|
||||
if( isset( $this->api_key ) && isset( $this->secret_key ) ) {
|
||||
|
||||
$this->auth = base64_encode( "{$this->api_key}:{$this->secret_key}" );
|
||||
|
||||
}
|
||||
|
||||
return $this->auth;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prepares Header for Request
|
||||
*
|
||||
* @since 2.7
|
||||
* @version 1.0
|
||||
*/
|
||||
private function get_headers() {
|
||||
|
||||
$auth = $this->get_auth();
|
||||
|
||||
return array(
|
||||
'Authorization' => "Basic {$auth}",
|
||||
'Content-Type' => 'application/json'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends Email using Mailjet transmissions end point
|
||||
*
|
||||
* @since 2.7
|
||||
* @version 1.0
|
||||
*/
|
||||
public function send( $content ) {
|
||||
|
||||
$content = json_encode( $content );
|
||||
|
||||
return $this->request(
|
||||
'POST',
|
||||
'/send',
|
||||
$this->get_headers(),
|
||||
$content,
|
||||
$this->email_sent_code
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
class PostmanMailtrap extends PostmanServiceRequest {
|
||||
|
||||
/**
|
||||
* Success Code
|
||||
*
|
||||
* @since 2.9.0
|
||||
* @version 1.0
|
||||
*/
|
||||
private $email_sent_code = 200;
|
||||
|
||||
/**
|
||||
* API Key
|
||||
*
|
||||
* @since 2.9.0
|
||||
* @version 1.0
|
||||
*/
|
||||
private $api_key = '';
|
||||
|
||||
/**
|
||||
* Base URL
|
||||
*
|
||||
* @since 2.9.0
|
||||
* @version 1.0
|
||||
*/
|
||||
private $base_url = 'https://send.api.mailtrap.io/api';
|
||||
|
||||
/**
|
||||
* constructor PostmanMailtrap
|
||||
*
|
||||
* @param $api_key
|
||||
* @since 2.9.0
|
||||
* @version 1.0
|
||||
*/
|
||||
public function __construct( $api_key ) {
|
||||
|
||||
$this->api_key = $api_key;
|
||||
|
||||
parent::__construct( $this->base_url );
|
||||
|
||||
// Set timeout for API requests
|
||||
$this->set_additional_args( array(
|
||||
'timeout' => 30
|
||||
) );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares Header for Request
|
||||
*
|
||||
* @since 2.9.0
|
||||
* @version 1.0
|
||||
*/
|
||||
private function get_headers() {
|
||||
|
||||
return array(
|
||||
'Api-Token' => $this->api_key,
|
||||
'Content-Type' => 'application/json',
|
||||
'Accept' => 'application/json'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends Email using Mailtrap send endpoint
|
||||
*
|
||||
* @param array $content
|
||||
* @since 2.9.0
|
||||
* @version 1.0
|
||||
*/
|
||||
public function send( $content ) {
|
||||
|
||||
$content = json_encode( $content );
|
||||
|
||||
if ( $content === false ) {
|
||||
throw new Exception( 'Failed to encode email content to JSON' );
|
||||
}
|
||||
|
||||
return $this->request(
|
||||
'POST',
|
||||
'/send',
|
||||
$this->get_headers(),
|
||||
$content,
|
||||
$this->email_sent_code
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
class PostmanMandrill extends PostmanServiceRequest {
|
||||
|
||||
/**
|
||||
* Success Code
|
||||
*
|
||||
* @since 2.2
|
||||
* @version 1.0
|
||||
*/
|
||||
private $email_sent_code = 200;
|
||||
|
||||
/**
|
||||
* API Key
|
||||
*
|
||||
* @since 2.2
|
||||
* @version 1.0
|
||||
*/
|
||||
private $api_key = '';
|
||||
|
||||
/**
|
||||
* Base URL
|
||||
*
|
||||
* @since 2.2
|
||||
* @version 1.0
|
||||
*/
|
||||
private $base_url = 'https://mandrillapp.com/api/1.0';
|
||||
|
||||
/**
|
||||
* constructor PostmanMandril
|
||||
*
|
||||
* @param $api_key
|
||||
* @since 2.2
|
||||
* @version 1.0
|
||||
*/
|
||||
public function __construct( $api_key ) {
|
||||
|
||||
$this->api_key = $api_key;
|
||||
|
||||
parent::__construct( $this->base_url );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares Header for Request
|
||||
*
|
||||
* @since 2.2
|
||||
* @version 1.0
|
||||
*/
|
||||
private function get_headers() {
|
||||
|
||||
return array(
|
||||
'Content-Type' => 'application/json',
|
||||
'Accept' => 'application/json',
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends Email using PostMark email end point
|
||||
*
|
||||
* @param $api_key
|
||||
* @since 2.2
|
||||
* @version 1.0
|
||||
*/
|
||||
public function send( $content ) {
|
||||
$content = json_encode( $content );
|
||||
|
||||
return $this->request(
|
||||
'POST',
|
||||
'/messages/send.json',
|
||||
$this->get_headers(),
|
||||
$content,
|
||||
$this->email_sent_code
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
class PostmanPostMark extends PostmanServiceRequest {
|
||||
|
||||
/**
|
||||
* Success Code
|
||||
*
|
||||
* @since 2.2
|
||||
* @version 1.0
|
||||
*/
|
||||
private $email_sent_code = 200;
|
||||
|
||||
/**
|
||||
* API Key
|
||||
*
|
||||
* @since 2.2
|
||||
* @version 1.0
|
||||
*/
|
||||
private $api_key = '';
|
||||
|
||||
/**
|
||||
* Base URL
|
||||
*
|
||||
* @since 2.2
|
||||
* @version 1.0
|
||||
*/
|
||||
private $base_url = 'https://api.postmarkapp.com';
|
||||
|
||||
/**
|
||||
* constructor PostmanPostMark
|
||||
*
|
||||
* @param $api_key
|
||||
* @since 2.2
|
||||
* @version 1.0
|
||||
*/
|
||||
public function __construct( $api_key ) {
|
||||
|
||||
$this->api_key = $api_key;
|
||||
|
||||
parent::__construct( $this->base_url );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares Header for Request
|
||||
*
|
||||
* @since 2.2
|
||||
* @version 1.0
|
||||
*/
|
||||
private function get_headers() {
|
||||
|
||||
return array(
|
||||
'X-Postmark-Server-Token' => $this->api_key,
|
||||
'Content-Type' => 'application/json',
|
||||
'Accept' => 'application/json',
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends Email using PostMark email end point
|
||||
*
|
||||
* @param $api_key
|
||||
* @since 2.2
|
||||
* @version 1.0
|
||||
*/
|
||||
public function send( $content ) {
|
||||
|
||||
/**
|
||||
* Filters the content before sending
|
||||
*
|
||||
* @since 2.9.2
|
||||
*/
|
||||
$content = json_encode( apply_filters( 'post_smtp_postmark_content' , $content ) );
|
||||
|
||||
return $this->request(
|
||||
'POST',
|
||||
'/email',
|
||||
$this->get_headers(),
|
||||
$content,
|
||||
$this->email_sent_code
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
|
||||
class PostmanServiceRequest {
|
||||
|
||||
|
||||
/**
|
||||
* Base URL
|
||||
*
|
||||
* @since 2.2
|
||||
* @version 1.0
|
||||
*/
|
||||
private $base_url = '';
|
||||
|
||||
/**
|
||||
* Additional Args
|
||||
*
|
||||
* @since 2.2
|
||||
* @version 1.0
|
||||
*/
|
||||
private $additional_args = array();
|
||||
|
||||
/**
|
||||
* Request Response
|
||||
*
|
||||
* @since 2.2
|
||||
* @version 1.0
|
||||
*/
|
||||
private $response = array();
|
||||
|
||||
/**
|
||||
* constructor PostmanServiceRequest
|
||||
*
|
||||
* @param $base_url
|
||||
* @since 2.2
|
||||
* @version 1.0
|
||||
*/
|
||||
public function __construct( $base_url ) {
|
||||
|
||||
$this->base_url = $base_url;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Additional Args
|
||||
*
|
||||
* @param $args
|
||||
* @since 2.2
|
||||
* @version 1.0
|
||||
*/
|
||||
public function set_additional_args( $args ) {
|
||||
|
||||
$this->additional_args = $args;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes Remote Request
|
||||
*
|
||||
* @param $method
|
||||
* @param $end_point
|
||||
* @param $headers
|
||||
* @param $body
|
||||
* @param $success_code
|
||||
* @since 2.2
|
||||
* @version 1.0
|
||||
*/
|
||||
public function request( $method, $end_point, $headers = array(), $body = array(), $success_code = 200 ) {
|
||||
|
||||
$url = "{$this->base_url}{$end_point}";
|
||||
$args = array(
|
||||
'method' => $method,
|
||||
'headers' => $headers,
|
||||
'body' => $body
|
||||
);
|
||||
|
||||
//Set Additional Args (If Set)
|
||||
if( !empty( $this->additional_args ) ) {
|
||||
|
||||
$args = array_merge( $this->additional_args, $args );
|
||||
|
||||
}
|
||||
|
||||
$this->response = wp_remote_post(
|
||||
$url,
|
||||
$args
|
||||
);
|
||||
|
||||
$response_code = $this->get_response_code();
|
||||
|
||||
if( $response_code == $success_code ) {
|
||||
|
||||
return $this->response;
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
$this->exception();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets Reponse Code
|
||||
*
|
||||
* @since 2.2
|
||||
* @version 1.0
|
||||
*/
|
||||
public function get_response_code() {
|
||||
|
||||
return wp_remote_retrieve_response_code( $this->response );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets Response message
|
||||
*
|
||||
* @since 2.2
|
||||
* @version 1.0
|
||||
*/
|
||||
public function get_response_message() {
|
||||
|
||||
return wp_remote_retrieve_response_message( $this->response );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets Response Body
|
||||
*
|
||||
* @since 2.2
|
||||
* @version 1.0
|
||||
*/
|
||||
public function get_response_body() {
|
||||
|
||||
return wp_remote_retrieve_body( $this->response );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create and throw Exception
|
||||
*
|
||||
* @since 2.2
|
||||
* @version 1.0
|
||||
*/
|
||||
public function exception() {
|
||||
|
||||
$message = "Code: {$this->get_response_code()}, Message: {$this->get_response_message()}, Body: {$this->get_response_body()}";
|
||||
|
||||
throw new Exception( $message );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
class PostmanResend extends PostmanServiceRequest {
|
||||
|
||||
/**
|
||||
* Success Code
|
||||
*
|
||||
* @since 3.2.0
|
||||
* @version 1.0
|
||||
*/
|
||||
private $email_sent_code = 200;
|
||||
|
||||
/**
|
||||
* API Key
|
||||
*
|
||||
* @since 3.2.0
|
||||
* @version 1.0
|
||||
*/
|
||||
private $api_key = '';
|
||||
|
||||
/**
|
||||
* Base URL
|
||||
*
|
||||
* @since 3.2.0
|
||||
* @version 1.0
|
||||
*/
|
||||
private $base_url = 'https://api.resend.com';
|
||||
|
||||
/**
|
||||
* constructor PostmanResend
|
||||
*
|
||||
* @param $api_key
|
||||
* @since 3.2.0
|
||||
* @version 1.0
|
||||
*/
|
||||
public function __construct( $api_key ) {
|
||||
|
||||
$this->api_key = $api_key;
|
||||
|
||||
parent::__construct( $this->base_url );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares Header for Request
|
||||
*
|
||||
* @since 3.2.0
|
||||
* @version 1.0
|
||||
*/
|
||||
private function get_headers() {
|
||||
|
||||
return array(
|
||||
'Authorization' => 'Bearer ' . $this->api_key,
|
||||
'Content-Type' => 'application/json'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends Email using Resend emails endpoint
|
||||
*
|
||||
* @param $content
|
||||
* @since 3.2.0
|
||||
* @version 1.0
|
||||
*/
|
||||
public function send( $content ) {
|
||||
|
||||
$content = json_encode( $content );
|
||||
|
||||
return $this->request(
|
||||
'POST',
|
||||
'/emails',
|
||||
$this->get_headers(),
|
||||
$content,
|
||||
$this->email_sent_code
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
class PostmanSendGrid extends PostmanServiceRequest {
|
||||
|
||||
/**
|
||||
* Success Code
|
||||
*
|
||||
* @since 2.4
|
||||
* @version 1.0
|
||||
*/
|
||||
private $email_sent_code = 202;
|
||||
|
||||
/**
|
||||
* API Key
|
||||
*
|
||||
* @since 2.4
|
||||
* @version 1.0
|
||||
*/
|
||||
private $api_key = '';
|
||||
|
||||
/**
|
||||
* Base URL
|
||||
*
|
||||
* @since 2.4
|
||||
* @version 1.0
|
||||
*/
|
||||
private $base_url = 'https://api.sendgrid.com/v3/mail';
|
||||
|
||||
/**
|
||||
* Options instance
|
||||
*
|
||||
* @var PostmanOptions
|
||||
*/
|
||||
private $options;
|
||||
|
||||
/**
|
||||
* constructor PostmanSendGrid
|
||||
*
|
||||
* @param $api_key
|
||||
* @since 2.4
|
||||
* @version 1.0
|
||||
*/
|
||||
public function __construct( $api_key ) {
|
||||
|
||||
$this->api_key = $api_key;
|
||||
$this->options = PostmanOptions::getInstance();
|
||||
$region = $this->options->getSendGridRegion();
|
||||
|
||||
if ( 'EU' === $region || apply_filters( 'post_smtp_enable_sendgrid_eu', false ) ) {
|
||||
$this->base_url = 'https://api.eu.sendgrid.com/v3/mail';
|
||||
}
|
||||
|
||||
$this->base_url = apply_filters( 'post_smtp_sendgrid_base_url', $this->base_url, $region );
|
||||
parent::__construct( $this->base_url );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares Header for Request
|
||||
*
|
||||
* @since 2.4
|
||||
* @version 1.0
|
||||
*/
|
||||
private function get_headers() {
|
||||
|
||||
return array(
|
||||
'Content-Type' => 'application/json',
|
||||
'Authorization' => 'Bearer ' . $this->api_key
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends Email using SendGrid email end point
|
||||
*
|
||||
* @param $api_key
|
||||
* @since 2.4
|
||||
* @version 1.0
|
||||
*/
|
||||
public function send( $content ) {
|
||||
|
||||
$content = json_encode( $content );
|
||||
|
||||
return $this->request(
|
||||
'POST',
|
||||
'/send',
|
||||
$this->get_headers(),
|
||||
$content,
|
||||
$this->email_sent_code
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
class PostmanSendpulse extends PostmanServiceRequest {
|
||||
|
||||
/**
|
||||
* Success Code
|
||||
*
|
||||
* @since 2.9.0
|
||||
* @version 1.0
|
||||
*/
|
||||
private $email_sent_code = 200;
|
||||
|
||||
/**
|
||||
* API Key and Secret Key
|
||||
*
|
||||
* @since 2.9.0
|
||||
* @version 1.0
|
||||
*/
|
||||
private $api_key = ' ';
|
||||
private $secret_key = ' ';
|
||||
|
||||
|
||||
/**
|
||||
* Parameters used to get Token
|
||||
*
|
||||
* @since 2.9.0
|
||||
* @version 1.0
|
||||
*/
|
||||
private $grant_type = 'client_credentials';
|
||||
private $auth_response_body = ' ';
|
||||
private $auth_response = ' ';
|
||||
private $token = ' ';
|
||||
|
||||
/**
|
||||
* Base URL
|
||||
*
|
||||
* @since 2.9.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
private $base_url = 'https://api.sendpulse.com';
|
||||
|
||||
|
||||
/**
|
||||
* Constructor PostmanSendpulse
|
||||
*
|
||||
* @param mixed $api_key Api Key.
|
||||
* @param mixed $secret_key Secret Key.
|
||||
* @since 2.9.0
|
||||
* @version 1.0
|
||||
*/
|
||||
public function __construct( $api_key, $secret_key )
|
||||
{
|
||||
|
||||
$this->api_key = $api_key;
|
||||
$this->secret_key = $secret_key;
|
||||
parent::__construct( $this->base_url );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Header to get token
|
||||
*
|
||||
* @since 2.9.0
|
||||
* @version 1.0
|
||||
*/
|
||||
private function auth_headers() {
|
||||
|
||||
return array(
|
||||
'Content-Type' => 'application/json'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Body to get token
|
||||
*
|
||||
* @since 2.9.0
|
||||
* @version 1.0
|
||||
*/
|
||||
private function auth_body() {
|
||||
|
||||
return array(
|
||||
'grant_type' => $this->grant_type,
|
||||
'client_id' => $this->api_key,
|
||||
'client_secret' => $this->secret_key
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Authenciation to get Token
|
||||
*
|
||||
* @since 2.9.0
|
||||
* @version 1.0
|
||||
*/
|
||||
private function authentication() {
|
||||
|
||||
$content = json_encode( $this->auth_body() );
|
||||
|
||||
$this->auth_response_body = $this->request(
|
||||
'POST',
|
||||
'/oauth/access_token',
|
||||
$this->auth_headers(),
|
||||
$content,
|
||||
$this->email_sent_code
|
||||
|
||||
);
|
||||
|
||||
$this->auth_response = json_decode( $this->auth_response_body['body'], true );
|
||||
|
||||
//Auto delete token when token expires after given time period.
|
||||
|
||||
set_transient( 'sendpulse_token', $this->auth_response['access_token'], $this->auth_response['expires_in'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares Header for Request
|
||||
*
|
||||
* @since 2.9.0
|
||||
* @version 1.0
|
||||
*/
|
||||
private function get_headers()
|
||||
{
|
||||
|
||||
if ( get_transient('sendpulse_token') ) {
|
||||
|
||||
$this->token = get_transient( 'sendpulse_token' );
|
||||
} else {
|
||||
|
||||
$this->authentication();
|
||||
$this->token = get_transient( 'sendpulse_token' );
|
||||
}
|
||||
|
||||
return array(
|
||||
|
||||
'Content-Type' => 'application/json',
|
||||
'Authorization' => 'Bearer ' . $this->token
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends Email using Sendpulse transmissions end point
|
||||
*
|
||||
* @param mixed $content
|
||||
* @since 2.9.0
|
||||
* @version 1.0
|
||||
*/
|
||||
public function send( $content ) {
|
||||
|
||||
$content = json_encode( $content );
|
||||
|
||||
return $this->request(
|
||||
'POST',
|
||||
'/smtp/emails',
|
||||
$this->get_headers(),
|
||||
$content,
|
||||
$this->email_sent_code
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
class PostmanSendinblue extends PostmanServiceRequest {
|
||||
|
||||
/**
|
||||
* Success Code
|
||||
*
|
||||
* @since 2.3
|
||||
* @version 1.0
|
||||
*/
|
||||
private $email_sent_code = 201;
|
||||
|
||||
/**
|
||||
* API Key
|
||||
*
|
||||
* @since 2.3
|
||||
* @version 1.0
|
||||
*/
|
||||
private $api_key = '';
|
||||
|
||||
/**
|
||||
* Base URL
|
||||
*
|
||||
* @since 2.3
|
||||
* @version 1.0
|
||||
*/
|
||||
private $base_url = 'https://api.brevo.com/v3/smtp';
|
||||
|
||||
/**
|
||||
* constructor PostmanSendinblue
|
||||
*
|
||||
* @param $api_key
|
||||
* @since 2.3
|
||||
* @version 1.0
|
||||
*/
|
||||
public function __construct( $api_key ) {
|
||||
|
||||
$this->api_key = $api_key;
|
||||
|
||||
parent::__construct( $this->base_url );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares Header for Request
|
||||
*
|
||||
* @since 2.3
|
||||
* @version 1.0
|
||||
*/
|
||||
private function get_headers() {
|
||||
|
||||
return array(
|
||||
'Api-Key' => $this->api_key,
|
||||
'Content-Type' => 'application/json',
|
||||
'Accept' => 'application/json'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends Email using Sendinblue transmissions end point
|
||||
*
|
||||
* @param $api_key
|
||||
* @since 2.3
|
||||
* @version 1.0
|
||||
*/
|
||||
public function send( $content ) {
|
||||
|
||||
$content = json_encode( $content );
|
||||
|
||||
return $this->request(
|
||||
'POST',
|
||||
'/email',
|
||||
$this->get_headers(),
|
||||
$content,
|
||||
$this->email_sent_code
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
/**
|
||||
* PostmanSmtp2GoHandler
|
||||
*
|
||||
* @package Postman
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
if ( ! class_exists( 'PostmanSmtp2GoHandler' ) ) {
|
||||
class PostmanSmtp2GoHandler extends PostmanServiceRequest {
|
||||
private $email_sent_code = 200;
|
||||
private $api_key = '';
|
||||
private $base_url = 'https://api.smtp2go.com/v3/email';
|
||||
|
||||
public function __construct( $api_key ) {
|
||||
$this->api_key = $api_key;
|
||||
|
||||
parent::__construct( $this->base_url );
|
||||
|
||||
// Set 30-second timeout for SMTP2GO requests
|
||||
$this->set_additional_args( array( 'timeout' => 30 ) );
|
||||
}
|
||||
|
||||
private function get_headers() {
|
||||
return array(
|
||||
'Content-Type' => 'application/json',
|
||||
'X-Smtp2go-Api-Key' => $this->api_key,
|
||||
'accept' => 'application/json',
|
||||
);
|
||||
}
|
||||
|
||||
public function send( $content ) {
|
||||
$content = json_encode( $content );
|
||||
|
||||
return $this->request(
|
||||
'POST',
|
||||
'/send',
|
||||
$this->get_headers(),
|
||||
$content,
|
||||
$this->email_sent_code
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
class PostmanSparkPost extends PostmanServiceRequest {
|
||||
|
||||
/**
|
||||
* Success Code
|
||||
*
|
||||
* @since 2.2
|
||||
* @version 1.0
|
||||
*/
|
||||
private $email_sent_code = 200;
|
||||
|
||||
/**
|
||||
* API Key
|
||||
*
|
||||
* @since 2.2
|
||||
* @version 1.0
|
||||
*/
|
||||
private $api_key = '';
|
||||
|
||||
/**
|
||||
* Base URL
|
||||
*
|
||||
* @since 2.2
|
||||
* @version 1.0
|
||||
*/
|
||||
private $base_url = 'https://api.sparkpost.com/api/v1';
|
||||
|
||||
/**
|
||||
* Base URL for Global Region
|
||||
*
|
||||
* @since 2.2
|
||||
* @version 1.0
|
||||
*/
|
||||
private $base_url_us = 'https://api.sparkpost.com/api/v1';
|
||||
|
||||
/**
|
||||
* Base URL for Europe Region
|
||||
*
|
||||
* @since 2.2
|
||||
* @version 1.0
|
||||
*/
|
||||
private $base_url_eu = 'https://api.eu.sparkpost.com/api/v1';
|
||||
|
||||
/**
|
||||
* constructor PostmanSparkPost
|
||||
*
|
||||
* @param $api_key
|
||||
* @since 2.2
|
||||
* @version 1.0
|
||||
*/
|
||||
public function __construct( $api_key ) {
|
||||
|
||||
$this->api_key = $api_key;
|
||||
|
||||
parent::__construct( $this->base_url );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares Header for Request
|
||||
*
|
||||
* @since 2.2
|
||||
* @version 1.0
|
||||
*/
|
||||
private function get_headers() {
|
||||
|
||||
return array(
|
||||
'Authorization' => $this->api_key,
|
||||
'Content-Type' => 'application/json'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends Email using SparkPost transmissions end point
|
||||
*
|
||||
* @param $api_key
|
||||
* @since 2.2
|
||||
* @version 1.0
|
||||
*/
|
||||
public function send( $content ) {
|
||||
|
||||
$content = json_encode( $content );
|
||||
|
||||
return $this->request(
|
||||
'POST',
|
||||
'/transmissions',
|
||||
$this->get_headers(),
|
||||
$content,
|
||||
$this->email_sent_code
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
class PostmanSweego extends PostmanServiceRequest {
|
||||
/**
|
||||
* Success Code
|
||||
*/
|
||||
private $email_sent_code = 200;
|
||||
|
||||
/**
|
||||
* API Key
|
||||
*/
|
||||
private $api_key = '';
|
||||
|
||||
/**
|
||||
* Base URL (endpoint)
|
||||
*/
|
||||
private $base_url = 'https://api.sweego.io';
|
||||
|
||||
/**
|
||||
* Options instance
|
||||
* @var PostmanOptions
|
||||
*/
|
||||
private $options;
|
||||
|
||||
/**
|
||||
* constructor PostmanSweego
|
||||
* @param $api_key
|
||||
* @param $endpoint
|
||||
*/
|
||||
public function __construct( $api_key ) {
|
||||
$this->api_key = $api_key;
|
||||
parent::__construct( $this->base_url );
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares Header for Request
|
||||
*/
|
||||
private function get_headers() {
|
||||
return array(
|
||||
'Content-Type' => 'application/json',
|
||||
'Accept' => 'application/json',
|
||||
'Api-Key' => $this->api_key
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends Email using Sweego API
|
||||
* @param $content
|
||||
* @return mixed
|
||||
*/
|
||||
public function send( $content ) {
|
||||
$content = json_encode( $content );
|
||||
return $this->request(
|
||||
'POST',
|
||||
'/send',
|
||||
$this->get_headers(),
|
||||
$content,
|
||||
$this->email_sent_code
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user