Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
Merge branch 'release/1.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
luchaos committed Oct 1, 2019
2 parents e611ab3 + 9e85974 commit ca0afb2
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 13 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Release Notes

## v1.3.0 (2019-09-30)
### Added
- Preauthorize/Capture/Void transaction request option
- Plugin author, WooCommerce minimum & tested up to version
### Changed
- Unified payment failure response

## v1.2.0 (2019-09-10)
### Added
- [README](README.md) note on enabling/disabling additional adapters
Expand Down
2 changes: 1 addition & 1 deletion build.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* extension source version
*/
$version = '1.2.0';
$version = '1.3.0';

/**
* dist filename
Expand Down
59 changes: 48 additions & 11 deletions src/classes/includes/payment-gateway-cloud-creditcard.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,21 @@ public function process_payment($orderId)
}

/**
* debit
* transaction
*/
$debit = new \PaymentGatewayCloud\Client\Transaction\Debit();
$debit->setTransactionId($orderId)
$transactionRequest = $this->get_option('transactionRequest');
$transaction = null;
switch ($transactionRequest) {
case 'preauthorize':
$transaction = new \PaymentGatewayCloud\Client\Transaction\Preauthorize();
break;
case 'debit':
default:
$transaction = new \PaymentGatewayCloud\Client\Transaction\Debit();
break;
}

$transaction->setTransactionId($orderId)
->setAmount(floatval($this->order->get_total()))
->setCurrency($this->order->get_currency())
->setCustomer($customer)
Expand All @@ -131,21 +142,29 @@ public function process_payment($orderId)
'redirect' => $this->order->get_checkout_payment_url(false),
];
}
$debit->setTransactionToken($token);
$transaction->setTransactionToken($token);
}

/**
* transaction
*/
$result = $client->debit($debit);
switch ($transactionRequest) {
case 'preauthorize':
$result = $client->preauthorize($transaction);
break;
case 'debit':
default:
$result = $client->debit($transaction);
break;
}

if ($result->isSuccess()) {
$woocommerce->cart->empty_cart();

$gatewayReferenceId = $result->getReferenceId();
// $gatewayReferenceId = $result->getReferenceId();
if ($result->getReturnType() == PaymentGatewayCloud\Client\Transaction\Result::RETURN_TYPE_ERROR) {
$errors = $result->getErrors();
$this->order->update_status('failed', __('Payment failed or was declined', 'woocommerce'));
// $errors = $result->getErrors();
return $this->paymentFailedResponse();
} elseif ($result->getReturnType() == PaymentGatewayCloud\Client\Transaction\Result::RETURN_TYPE_REDIRECT) {
return [
'result' => 'success',
Expand All @@ -166,9 +185,16 @@ public function process_payment($orderId)
/**
* something went wrong
*/
wp_send_json_error([
'error' => $result->getFirstError()->getMessage(),
]);
return $this->paymentFailedResponse();
}

private function paymentFailedResponse()
{
$this->order->update_status('failed', __('Payment failed or was declined', 'woocommerce'));
return [
'result' => 'error',
'redirect' => $this->get_return_url($this->order),
];
}

public function process_callback()
Expand Down Expand Up @@ -245,6 +271,17 @@ public function init_form_fields()
'description' => 'Integration Key',
'default' => '',
],
'transactionRequest' => [
'title' => 'Transaction Request',
'type' => 'select',
'label' => 'Transaction Request',
'description' => 'Transaction Request',
'default' => 'debit',
'options' => [
'debit' => 'Debit',
'preauthorize' => 'Preauthorize/Capture/Void',
],
],
];
}

Expand Down
4 changes: 3 additions & 1 deletion src/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
Contributors: Payment Gateway Cloud
Tags: Credit Card, e-commerce, payment, checkout
Requires at least: 4.9
Tested up to: 5.0.4
Tested up to: 5.2.3
Requires PHP: 7.1
Stable tag: X.Y.Z
WC requires at least: 3.6.0
WC tested up to: 3.7.0

Payment Gateway Cloud WooCommerce Extension

Expand Down
3 changes: 3 additions & 0 deletions src/woocommerce-payment-gateway-cloud.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* Plugin Name: WooCommerce Payment Gateway Cloud Extension
* Description: Payment Gateway Cloud for WooCommerce
* Version: X.Y.Z
* Author: Payment Gateway Cloud
* WC requires at least: 3.6.0
* WC tested up to: 3.7.0
*/
if (!defined('ABSPATH')) {
exit;
Expand Down

0 comments on commit ca0afb2

Please sign in to comment.