1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Authorize a card with Paytrace

This commit is contained in:
David Bomba 2021-07-21 15:34:20 +10:00
parent 87e1ba48e9
commit f0b232c1a2
3 changed files with 56 additions and 24 deletions

View File

@ -51,8 +51,6 @@ class CreditCard
{
$data = $request->all();
nlog($data);
$post_data = [
'customer_id' => Str::random(32),
'hpf_token' => $data['HPF_Token'],
@ -67,8 +65,6 @@ class CreditCard
],
];
nlog($post_data);
// "_token" => "Vl1xHflBYQt9YFSaNCPTJKlY5x3rwcFE9kvkw71I"
// "company_gateway_id" => "1"
// "HPF_Token" => "e484a92c-90ed-4468-ac4d-da66824c75de"
@ -93,10 +89,30 @@ class CreditCard
// dd($response);
// +"success": true
// +"response_code": 160
// +"status_message": "The customer profile for PLS5U60OoLUfQXzcmtJYNefPA0gTthzT/11 was successfully created."
// +"customer_id": "PLS5U60OoLUfQXzcmtJYNefPA0gTthzT"
// +"success": true
// +"response_code": 160
// +"status_message": "The customer profile for PLS5U60OoLUfQXzcmtJYNefPA0gTthzT/11 was successfully created."
// +"customer_id": "PLS5U60OoLUfQXzcmtJYNefPA0gTthzT"
// if(!$response->success)
//handle failure
$cgt = [];
$cgt['token'] = $response->customer_id;
$cgt['payment_method_id'] = GatewayType::CREDIT_CARD;
$profile = $this->getCustomerProfile($response->customer_id);
$payment_meta = new \stdClass;
$payment_meta->exp_month = $profile->credit_card->expiration_month;
$payment_meta->exp_year = $profile->credit_card->expiration_year;
$payment_meta->brand = 'CC';
$payment_meta->last4 = $profile->credit_card->masked_number;
$payment_meta->type = GatewayType::CREDIT_CARD;
$cgt['payment_meta'] = $payment_meta;
$token = $this->paytrace_driver->storeGatewayToken($cgt, []);
// make a cc card out of that bra
@ -104,6 +120,19 @@ class CreditCard
}
private function getCustomerProfile($customer_id)
{
$profile = $this->paytrace_driver->gatewayRequest('/v1/customer/export', [
'integrator_id' => '959195xd1CuC',
'customer_id' => $customer_id,
// 'include_bin' => true,
]);
return $profile->customers[0];
}
public function paymentView($data)
{

View File

@ -123,20 +123,21 @@ class PaytracePaymentDriver extends BaseDriver
public function getAuthToken()
{
$headers = $this->generateAuthHeaders();
$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);
if($response)
return $response->clientKey;
if($response)
return $response->clientKey;
return false;
}
public function gatewayRequest($uri, $data, $headers = false)
{
$base_url = "https://api.paytrace.com{$uri}";
$headers = $this->generateAuthHeaders();
@ -149,5 +150,6 @@ class PaytracePaymentDriver extends BaseDriver
return $response;
return false;
}
}

View File

@ -84,9 +84,9 @@ 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.getControl("securityCode").label.text("{!! ctrans('texts.cvv')!!}");
PTPayment.getControl("creditCard").label.text("{!! ctrans('texts.card_number')!!}");
PTPayment.getControl("expiration").label.text("{!! ctrans('texts.expires')!!}");
//PTPayment.style({'cc': {'label_color': 'red'}});
//PTPayment.style({'code': {'label_color': 'red'}});
//PTPayment.style({'exp': {'label_color': 'red'}});
@ -100,12 +100,15 @@ PTPayment.setup({
// 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'}});
}
let errors = document.getElementById('errors');
errors.textContent = '';
errors.textContent = validationErrors[0].description;
errors.hidden = false;
} else {
// no error so tokenize
instance.process()
@ -123,9 +126,7 @@ PTPayment.setup({
function handleError(err){
document.write(JSON.stringify(err));
document.write(JSON.stringify(err));
}
function submitPayment(r){