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.6.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
luchaos committed Oct 18, 2019
2 parents 46784ab + b2e9a8e commit 803277a
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 5 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

## Unreleased
### Changed
- Error return url redirect to checkout page with error message
- Set payment status more explicitly
- Unique order IDs in transaction
- Handle Void/Capture postback

## v1.5.0 (2019-10-17)
### Changed
- Remove redundant transaction request option read
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.5.0';
$version = '1.6.0';

/**
* dist filename
Expand Down
59 changes: 55 additions & 4 deletions src/classes/includes/payment-gateway-cloud-creditcard.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,33 @@ public function hide_payment_gateways_on_pay_for_order_page($available_gateways)
return $available_gateways;
}

private function encodeOrderId($orderId)
{
return $orderId . '-' . date('YmdHis') . substr(sha1(uniqid()), 0, 10);
}

private function decodeOrderId($orderId)
{
if (strpos($orderId, '-') === false) {
return $orderId;
}

$orderIdParts = explode('-', $orderId);

if(count($orderIdParts) === 2) {
$orderId = $orderIdParts[0];
}

/**
* void/capture will prefix the transaction id
*/
if(count($orderIdParts) === 3) {
$orderId = $orderIdParts[1];
}

return $orderId;
}

public function process_payment($orderId)
{
global $woocommerce;
Expand Down Expand Up @@ -136,15 +163,15 @@ public function process_payment($orderId)
break;
}

$transaction->setTransactionId($orderId)
$transaction->setTransactionId($this->encodeOrderId($orderId))
->setAmount(floatval($this->order->get_total()))
->setCurrency($this->order->get_currency())
->setCustomer($customer)
->setExtraData($this->extraData3DS())
->setCallbackUrl($this->callbackUrl)
->setCancelUrl(wc_get_checkout_url())
->setSuccessUrl($this->get_return_url($this->order))
->setErrorUrl($this->get_return_url($this->order));
->setErrorUrl(add_query_arg(['gateway_return_result' => 'error'], $this->order->get_checkout_payment_url(false)));

/**
* integration key is set -> seamless
Expand Down Expand Up @@ -227,9 +254,28 @@ public function process_callback()

$client->validateCallbackWithGlobals();
$callbackResult = $client->readCallback(file_get_contents('php://input'));
$this->order = new WC_Order($callbackResult->getTransactionId());
$this->order = new WC_Order($this->decodeOrderId($callbackResult->getTransactionId()));
if ($callbackResult->getResult() == \PaymentGatewayCloud\Client\Callback\Result::RESULT_OK) {
$this->order->payment_complete();
switch ($callbackResult->getTransactionType()) {
case \PaymentGatewayCloud\Client\Callback\Result::TYPE_DEBIT:
case \PaymentGatewayCloud\Client\Callback\Result::TYPE_CAPTURE:
$this->order->payment_complete();
break;
case \PaymentGatewayCloud\Client\Callback\Result::TYPE_VOID:
$this->order->update_status('cancelled', __('Void', 'woocommerce'));
break;
case \PaymentGatewayCloud\Client\Callback\Result::TYPE_PREAUTHORIZE:
$this->order->update_status('on-hold', __('Awaiting capture/void', 'woocommerce'));
break;
}
} elseif ($callbackResult->getResult() == \PaymentGatewayCloud\Client\Callback\Result::RESULT_ERROR) {
switch ($callbackResult->getTransactionType()) {
case \PaymentGatewayCloud\Client\Callback\Result::TYPE_DEBIT:
case \PaymentGatewayCloud\Client\Callback\Result::TYPE_CAPTURE:
case \PaymentGatewayCloud\Client\Callback\Result::TYPE_VOID:
$this->order->update_status('failed', __('Error', 'woocommerce'));
break;
}
}

die("OK");
Expand Down Expand Up @@ -381,6 +427,11 @@ private function extraData3DS()
// 3ds:browserTimezone
// 3ds:browserUserAgent

/**
* force 3ds flow
*/
// '3dsecure' => 'mandatory',

/**
* Additional 3ds 2.0 data
*/
Expand Down
10 changes: 10 additions & 0 deletions src/woocommerce-payment-gateway-cloud.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,14 @@
}
return $methods;
}, 0);

// add_filter('woocommerce_before_checkout_form', function(){
add_filter('the_content', function($content){
if(is_checkout_pay_page()) {
if(!empty($_GET['gateway_return_result']) && $_GET['gateway_return_result'] == 'error') {
wc_print_notice(__('Payment failed or was declined', 'woocommerce'), 'error');
}
}
return $content;
}, 0, 1);
});

0 comments on commit 803277a

Please sign in to comment.