mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-07 10:34:30 -04:00
Paytrace integration
This commit is contained in:
parent
0d52d57d41
commit
87e1ba48e9
@ -74,9 +74,9 @@ class PaymentWebhookRequest extends Request
|
|||||||
{
|
{
|
||||||
// For testing purposes we'll slow down the webhook processing by 2 seconds
|
// For testing purposes we'll slow down the webhook processing by 2 seconds
|
||||||
// to make sure webhook request doesn't came before our processing.
|
// to make sure webhook request doesn't came before our processing.
|
||||||
if (app()->environment() !== 'production') {
|
//if (app()->environment() !== 'production') {
|
||||||
sleep(2);
|
sleep(2);
|
||||||
}
|
//}
|
||||||
|
|
||||||
// Some gateways, like Checkout, we can dynamically pass payment hash,
|
// Some gateways, like Checkout, we can dynamically pass payment hash,
|
||||||
// which we will resolve here and get payment information from it.
|
// which we will resolve here and get payment information from it.
|
||||||
|
@ -41,6 +41,7 @@ class CreditCard
|
|||||||
{
|
{
|
||||||
|
|
||||||
$data['client_key'] = $this->paytrace_driver->getAuthToken();
|
$data['client_key'] = $this->paytrace_driver->getAuthToken();
|
||||||
|
$data['gateway'] = $this->paytrace_driver;
|
||||||
|
|
||||||
return render('gateways.paytrace.authorize', $data);
|
return render('gateways.paytrace.authorize', $data);
|
||||||
}
|
}
|
||||||
@ -50,7 +51,56 @@ class CreditCard
|
|||||||
{
|
{
|
||||||
$data = $request->all();
|
$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');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,8 +98,7 @@ class PaytracePaymentDriver extends BaseDriver
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*Helpers*/
|
/*Helpers*/
|
||||||
|
private function generateAuthHeaders()
|
||||||
public function getAuthToken()
|
|
||||||
{
|
{
|
||||||
|
|
||||||
$url = 'https://api.paytrace.com/oauth/token';
|
$url = 'https://api.paytrace.com/oauth/token';
|
||||||
@ -111,14 +110,21 @@ class PaytracePaymentDriver extends BaseDriver
|
|||||||
|
|
||||||
$response = CurlUtils::post($url, $data, $headers = false);
|
$response = CurlUtils::post($url, $data, $headers = false);
|
||||||
|
|
||||||
if($response)
|
$auth_data = json_decode($response);
|
||||||
{
|
|
||||||
$auth_data = json_decode($response);
|
|
||||||
|
|
||||||
$headers = [];
|
$headers = [];
|
||||||
$headers[] = 'Content-type: application/json';
|
$headers[] = 'Content-type: application/json';
|
||||||
$headers[] = 'Authorization: Bearer '.$auth_data->access_token;
|
$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 = CurlUtils::post('https://api.paytrace.com/v1/payment_fields/token/create', [], $headers);
|
||||||
|
|
||||||
$response = json_decode($response);
|
$response = json_decode($response);
|
||||||
@ -126,7 +132,21 @@ class PaytracePaymentDriver extends BaseDriver
|
|||||||
if($response)
|
if($response)
|
||||||
return $response->clientKey;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,8 @@
|
|||||||
@endif
|
@endif
|
||||||
|
|
||||||
<div class="alert alert-failure mb-4" hidden id="errors"></div>
|
<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">
|
<div class="w-screen items-center">
|
||||||
|
|
||||||
@ -18,11 +19,9 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<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=HPF_Token name= HPF_Token hidden>
|
||||||
<input type="txt" id=enc_key name = enc_key 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"/>
|
|
||||||
|
|
||||||
<div class="bg-white px-4 py-5 flex justify-end">
|
<div class="bg-white px-4 py-5 flex justify-end">
|
||||||
<button
|
<button
|
||||||
@ -85,43 +84,40 @@ PTPayment.setup({
|
|||||||
}).then(function(instance){
|
}).then(function(instance){
|
||||||
|
|
||||||
|
|
||||||
PTPayment.getControl("securityCode").label.text("CSC");
|
PTPayment.getControl("securityCode").label.text("CSC");
|
||||||
PTPayment.getControl("creditCard").label.text("CC#");
|
PTPayment.getControl("creditCard").label.text("CC#");
|
||||||
PTPayment.getControl("expiration").label.text("Exp Date");
|
PTPayment.getControl("expiration").label.text("Exp Date");
|
||||||
//PTPayment.style({'cc': {'label_color': 'red'}});
|
//PTPayment.style({'cc': {'label_color': 'red'}});
|
||||||
//PTPayment.style({'code': {'label_color': 'red'}});
|
//PTPayment.style({'code': {'label_color': 'red'}});
|
||||||
//PTPayment.style({'exp': {'label_color': 'red'}});
|
//PTPayment.style({'exp': {'label_color': 'red'}});
|
||||||
//PTPayment.style({'exp':{'type':'dropdown'}});
|
//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.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");
|
var enc_key = document.getElementById("enc_key");
|
||||||
hpf_token.value = r.message.hpf_token;
|
hpf_token.value = r.message.hpf_token;
|
||||||
enc_key.value = r.message.enc_key;
|
enc_key.value = r.message.enc_key;
|
||||||
document.getElementById("ProtectForm").submit();
|
|
||||||
|
document.getElementById("server_response").submit();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user