Paytrace integration

This commit is contained in:
David Bomba 2021-07-21 14:23:33 +10:00
parent 0d52d57d41
commit 87e1ba48e9
4 changed files with 117 additions and 50 deletions

View File

@ -74,9 +74,9 @@ class PaymentWebhookRequest extends Request
{
// For testing purposes we'll slow down the webhook processing by 2 seconds
// to make sure webhook request doesn't came before our processing.
if (app()->environment() !== 'production') {
//if (app()->environment() !== 'production') {
sleep(2);
}
//}
// Some gateways, like Checkout, we can dynamically pass payment hash,
// which we will resolve here and get payment information from it.

View File

@ -41,6 +41,7 @@ class CreditCard
{
$data['client_key'] = $this->paytrace_driver->getAuthToken();
$data['gateway'] = $this->paytrace_driver;
return render('gateways.paytrace.authorize', $data);
}
@ -50,7 +51,56 @@ class CreditCard
{
$data = $request->all();
return response()->json([], 200);
nlog($data);
$post_data = [
'customer_id' => Str::random(32),
'hpf_token' => $data['HPF_Token'],
'enc_key' => $data['enc_key'],
'integrator_id' => '959195xd1CuC',
'billing_address' => [
'name' => $this->paytrace_driver->client->present()->name(),
'street_address' => $this->paytrace_driver->client->address1,
'city' => $this->paytrace_driver->client->city,
'state' => $this->paytrace_driver->client->state,
'zip' => $this->paytrace_driver->client->postal_code
],
];
nlog($post_data);
// "_token" => "Vl1xHflBYQt9YFSaNCPTJKlY5x3rwcFE9kvkw71I"
// "company_gateway_id" => "1"
// "HPF_Token" => "e484a92c-90ed-4468-ac4d-da66824c75de"
// "enc_key" => "zqz6HMHCXALWdX5hyBqrIbSwU7TBZ0FTjjLB3Cp0FQY="
// "amount" => "Amount"
// "q" => "/client/payment_methods"
// "method" => "1"
// ]
// "customer_id":"customer789",
// "hpf_token":"e369847e-3027-4174-9161-fa0d4e98d318",
// "enc_key":"lI785yOBMet4Rt9o4NLXEyV84WBU3tdStExcsfoaOoo=",
// "integrator_id":"xxxxxxxxxx",
// "billing_address":{
// "name":"Mark Smith",
// "street_address":"8320 E. West St.",
// "city":"Spokane",
// "state":"WA",
// "zip":"85284"
// }
$response = $this->paytrace_driver->gatewayRequest('/v1/customer/pt_protect_create', $post_data);
// dd($response);
// +"success": true
// +"response_code": 160
// +"status_message": "The customer profile for PLS5U60OoLUfQXzcmtJYNefPA0gTthzT/11 was successfully created."
// +"customer_id": "PLS5U60OoLUfQXzcmtJYNefPA0gTthzT"
// make a cc card out of that bra
return redirect()->route('client.payment_methods.index');
}

View File

@ -98,8 +98,7 @@ class PaytracePaymentDriver extends BaseDriver
}
/*Helpers*/
public function getAuthToken()
private function generateAuthHeaders()
{
$url = 'https://api.paytrace.com/oauth/token';
@ -111,14 +110,21 @@ class PaytracePaymentDriver extends BaseDriver
$response = CurlUtils::post($url, $data, $headers = false);
if($response)
{
$auth_data = json_decode($response);
$auth_data = json_decode($response);
$headers = [];
$headers[] = 'Content-type: application/json';
$headers[] = 'Authorization: Bearer '.$auth_data->access_token;
return $headers;
}
public function getAuthToken()
{
$headers = $this->generateAuthHeaders();
$response = CurlUtils::post('https://api.paytrace.com/v1/payment_fields/token/create', [], $headers);
$response = json_decode($response);
@ -126,7 +132,21 @@ class PaytracePaymentDriver extends BaseDriver
if($response)
return $response->clientKey;
}
return false;
}
public function gatewayRequest($uri, $data, $headers = false)
{
$base_url = "https://api.paytrace.com{$uri}";
$headers = $this->generateAuthHeaders();
$response = CurlUtils::post($base_url, json_encode($data), $headers);
$response = json_decode($response);
if($response)
return $response;
return false;
}

View File

@ -10,7 +10,8 @@
@endif
<div class="alert alert-failure mb-4" hidden id="errors"></div>
<form action="{{ route('client.payment_methods.store', ['method' => App\Models\GatewayType::CREDIT_CARD]) }}" id="ProtectForm">
<form action="{{ route('client.payment_methods.store', ['method' => App\Models\GatewayType::CREDIT_CARD]) }}" method="post" id="server_response">
@csrf
<div class="w-screen items-center">
@ -18,11 +19,9 @@
</div>
<input type="txt" id=HPF_Token name= HPF_Token hidden>
<input type="txt" id=enc_key name = enc_key hidden>
<input type="txt" id=amount name = amount value="Amount"><br><br>
<input type="submit" value="Submit" id="SubmitButton"/>
<input type="hidden" name="company_gateway_id" value="{{ $gateway->company_gateway->id }}">
<input type="txt" id=HPF_Token name= HPF_Token hidden>
<input type="txt" id=enc_key name= enc_key hidden>
<div class="bg-white px-4 py-5 flex justify-end">
<button
@ -85,43 +84,40 @@ PTPayment.setup({
}).then(function(instance){
PTPayment.getControl("securityCode").label.text("CSC");
PTPayment.getControl("creditCard").label.text("CC#");
PTPayment.getControl("expiration").label.text("Exp Date");
//PTPayment.style({'cc': {'label_color': 'red'}});
//PTPayment.style({'code': {'label_color': 'red'}});
//PTPayment.style({'exp': {'label_color': 'red'}});
//PTPayment.style({'exp':{'type':'dropdown'}});
//PTPayment.theme('horizontal');
// this can be any event we chose. We will use the submit event and stop any default event handling and prevent event handling bubbling.
document.getElementById("ProtectForm").addEventListener("submit",function(e){
e.preventDefault();
e.stopPropagation();
// To trigger the validation of sensitive data payment fields within the iframe before calling the tokenization process:
PTPayment.validate(function(validationErrors) {
if (validationErrors.length >= 1) {
if (validationErrors[0]['responseCode'] == '35') {
// Handle validation Errors here
// This is an example of using dynamic styling to show the Credit card number entered is invalid
instance.style({'cc': {'border_color': 'red'}});
}
} else {
// no error so tokenize
instance.process()
.then( (r) => {
submitPayment(r);
}, (err) => {
handleError(err);
});
}
});
});
PTPayment.getControl("securityCode").label.text("CSC");
PTPayment.getControl("creditCard").label.text("CC#");
PTPayment.getControl("expiration").label.text("Exp Date");
//PTPayment.style({'cc': {'label_color': 'red'}});
//PTPayment.style({'code': {'label_color': 'red'}});
//PTPayment.style({'exp': {'label_color': 'red'}});
//PTPayment.style({'exp':{'type':'dropdown'}});
//PTPayment.theme('horizontal');
// this can be any event we chose. We will use the submit event and stop any default event handling and prevent event handling bubbling.
document.getElementById("server_response").addEventListener("submit",function(e){
e.preventDefault();
e.stopPropagation();
// To trigger the validation of sensitive data payment fields within the iframe before calling the tokenization process:
PTPayment.validate(function(validationErrors) {
if (validationErrors.length >= 1) {
if (validationErrors[0]['responseCode'] == '35') {
// Handle validation Errors here
// This is an example of using dynamic styling to show the Credit card number entered is invalid
instance.style({'cc': {'border_color': 'red'}});
}
} else {
// no error so tokenize
instance.process()
.then( (r) => {
submitPayment(r);
}, (err) => {
handleError(err);
});
}
});
});
});
@ -138,7 +134,8 @@ function submitPayment(r){
var enc_key = document.getElementById("enc_key");
hpf_token.value = r.message.hpf_token;
enc_key.value = r.message.enc_key;
document.getElementById("ProtectForm").submit();
document.getElementById("server_response").submit();
}