Skip to content

Instantly share code, notes, and snippets.

@maplerock
Created May 6, 2021 08:53
Show Gist options
  • Save maplerock/79714a5d41bccf54d79886033d0e0eb6 to your computer and use it in GitHub Desktop.
Save maplerock/79714a5d41bccf54d79886033d0e0eb6 to your computer and use it in GitHub Desktop.
Try Catch
<?php
use GlobalPayments\Api\Entities\Address;
use GlobalPayments\Api\Entities\Customer;
use GlobalPayments\Api\Entities\Exceptions\GatewayException;
use GlobalPayments\Api\ServiceConfigs\Gateways\GpEcomConfig;
use GlobalPayments\Api\ServicesContainer;
use WP_Error;
use WP_REST_Controller;
use WP_REST_Request;
use WP_REST_Response;
class RegisterCallbacks extends WP_REST_Controller {
public function registerRoutes() {
$namespace = 'mrd-elavon/v1';
add_filter( 'wp_should_handle_php_error', [$this,'example_callback'], 10, 3 );
register_rest_route( $namespace, '/methodNotificationUrl', array(
array(
'methods' => 'POST',
'callback' => array($this,'MethodNotification'),
'permission_callback' => '__return_true',
),
) );
register_rest_route( $namespace, '/challengeNotificationUrl', array(
array(
'methods' => 'POST',
'callback' => array($this,'ChallengeNotification'),
'permission_callback' => '__return_true',
),
));
register_rest_route( $namespace, '/StoreCustomer', array(
array(
'methods' => 'POST',
'callback' => array($this,'StoreCustomer'),
'permission_callback' => '__return_true',
),
));
}
public function MethodNotification(WP_REST_Request $request) {
$threeDSMethodData = $request["threeDSMethodData"];
$decodedThreeDSMethodData = base64_decode($threeDSMethodData);
$convertedThreeDSMethodData = json_decode($decodedThreeDSMethodData, true);
$serverTransID = $convertedThreeDSMethodData['threeDSServerTransID'];
$html = "<script src='".$this->getScriptPath()."'></script>";
$html .= "<script>";
$html .= "GlobalPayments.ThreeDSecure.handleMethodNotification(";
$html .= "{ threeDSServerTransID: '". $serverTransID ."'}";
$html .= ");";
$html .= "</script>";
$this->returnHtml($html);
}
public function StoreCustomer(WP_REST_Request $request) {
$config = new GpEcomConfig();
$config->merchantId = "";
$config->accountId = "";
$config->sharedSecret = "";
$config->environment = "TEST";
ServicesContainer::configureService($config);
//$charge_response->charge($paramBookingCode);
//save details to Elavon once processed payment
$this->customer = new Customer();
$this->customer->key = 1234;
$this->customer->title = "Mr.";
$this->customer->firstName = "James";
$this->customer->lastName = "Mason";
$this->customer->company = "Acme Ltd";
$this->customer->email = "text@example.com";
$this->customer->address = new Address();
$this->customer->address->streetAddress1 = "Flat 123";
$this->customer->address->streetAddress2 = "House 456";
$this->customer->address->city = "Halifax";
$this->customer->address->postalCode = "E77 4QJ";
$this->customer->address->country = "GB";
$this->customer->mobilePhone = "+353123456789";
try {
ray("try");
$response = $this->customer->create();
ray($response);
}
catch (GatewayException $e) {
ray($e);
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment