Skip to content

Commit

Permalink
Merge pull request #14 from xendit/fix/pipeline-yaml
Browse files Browse the repository at this point in the history
Fix/pipeline yaml
  • Loading branch information
andykim authored Apr 26, 2022
2 parents 1a0c83b + 738ce16 commit 7a5d107
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 63 deletions.
5 changes: 2 additions & 3 deletions .buddy/phpcodesniffer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
auto_clear_cache: true
fetch_all_refs: true
fail_on_prepare_env_warning: true
worker: "default_instance"
tags: []
worker_assignment: "FIXED"
actions:
Expand All @@ -25,9 +24,9 @@
- "# Fix violations of coding standards in PHP, JS and CSS files"
- "# Available coding standards: MySource, PEAR, PHPCS, PSR1, PSR2, Squiz and Zend"
- "# More options https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage"
- "phpcbf --standard=PSR2 --extensions=php ."
- "phpcbf --standard=PSR2 --ignore=*/vendor/* --extensions=php ."
- "# Detect without auto correction"
- "# phpcs -n --standard=PSR2 ."
- "phpcs -n --standard=PSR2 --ignore=*/vendor/* --extensions=php ."
setup_commands:
- "apt-get update && apt-get install -y git zip"
- "curl -L https://phar.phpunit.de/phpunit.phar -o /usr/local/bin/phpunit"
Expand Down
71 changes: 44 additions & 27 deletions .buddy/sonar-scan.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,48 @@
- pipeline: 'Static Application Security Testing'
trigger_mode: ON_EVERY_PUSH
ref_name: refs/pull/*
ref_type: WILDCARD
- pipeline: "Static Application Security Testing"
on: "EVENT"
events:
- type: "PUSH"
refs:
- "refs/heads/master"
- "refs/pull/*"
priority: "NORMAL"
auto_clear_cache: true
fetch_all_ref: true
trigger_condition: ALWAYS
fetch_all_refs: true
trigger_conditions:
- trigger_condition: "ALWAYS"
tags: []
worker_assignment: "FIXED"
actions:
- action: 'Run SAST'
type: RUN_DOCKER_CONTAINER
trigger_condition: VAR_IS
- action: "Run SAST"
type: "RUN_DOCKER_CONTAINER"
region: "ap-southeast-1"
docker_image_name: "xendit/sast"
docker_image_tag: "latest"
inline_commands: "run.sh"
volume_mappings:
- "/:/usr/deploy"
shell: "SH"
variables:
- key: "OWNER"
value: "store-channels"
type: "VAR"
trigger_conditions:
- trigger_condition: "VAR_IS"
trigger_variable_value: "master"
trigger_variable_key: "BUDDY_EXECUTION_PULL_REQUEST_BASE_BRANCH"
docker_image_name: xendit/sast
docker_image_tag: latest
integration_hash: 5e85761fc5f225000f97dd99
region: ap-southeast-1
inline_commands: run.sh
volume_mappings:
- '/:/usr/deploy'
variables:
- key: OWNER
value: store-channels
- action: "Send notification to channel"
type: "SLACK"
trigger_time: "ON_FAILURE"
content: "$BUDDY_PIPELINE_NAME execution failed. Please check details in Sonarqube"
blocks: "[{\"type\":\"section\",\"fields\":[{\"type\":\"mrkdwn\",\"text\":\"*Failed execution:* <$BUDDY_EXECUTION_URL|Execution #$BUDDY_EXECUTION_ID $BUDDY_EXECUTION_COMMENT>\"},{\"type\":\"mrkdwn\",\"text\":\"*Pipeline:* <$BUDDY_PIPELINE_URL|$BUDDY_PIPELINE_NAME>\"},{\"type\":\"mrkdwn\",\"text\":\"*Sonar Link:* <https://sonar.tidnex.com/project/issues?id=$BUDDY_PROJECT_NAME&resolved=false&types=VULNERABILITY&severities=BLOCKER|$BUDDY_PROJECT_NAME>\"},{\"type\":\"mrkdwn\",\"text\":\"*Project:* <$BUDDY_PROJECT_URL|$BUDDY_PROJECT_NAME>\"}]}]"
channel: "C01G4EK29QR"
trigger_condition: "ALWAYS"
integration_hash: "5ea6524a42eba4000eb35fbb"
zone_id: ""
trigger_hours: []
trigger_days: []
integration_hash: "5e85761fc5f225000f97dd99"
- action: "Send notification to channel"
type: "SLACK"
trigger_time: "ON_FAILURE"
content: "$BUDDY_PIPELINE_NAME execution failed. Please check details in Sonarqube"
blocks: "[{\"type\":\"section\",\"fields\":[{\"type\":\"mrkdwn\",\"text\":\"*Failed execution:* <$BUDDY_EXECUTION_URL|Execution #$BUDDY_EXECUTION_ID $BUDDY_EXECUTION_COMMENT>\"},{\"type\":\"mrkdwn\",\"text\":\"*Pipeline:* <$BUDDY_PIPELINE_URL|$BUDDY_PIPELINE_NAME>\"},{\"type\":\"mrkdwn\",\"text\":\"*Sonar Link:* <https://sonar.tidnex.com/project/issues?id=$BUDDY_PROJECT_NAME&resolved=false&types=VULNERABILITY&severities=BLOCKER|$BUDDY_PROJECT_NAME>\"},{\"type\":\"mrkdwn\",\"text\":\"*Project:* <$BUDDY_PROJECT_URL|$BUDDY_PROJECT_NAME>\"}]}]"
channel: "C01G4EK29QR"
trigger_conditions:
- trigger_condition: "ALWAYS"
zone_id: ""
trigger_hours: []
trigger_days: []
integration_hash: "5ea6524a42eba4000eb35fbb"
44 changes: 27 additions & 17 deletions modules/gateways/xendit/handler/updatecc.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@

$comparisonHash = sha1(
implode('|', [
$publicKey,
$customerId,
$invoiceId,
$amount,
$currencyCode,
$secretKey
$publicKey,
$customerId,
$invoiceId,
$amount,
$currencyCode,
$secretKey
])
);
if ($verificationHash !== $comparisonHash) {
Expand All @@ -60,7 +60,8 @@
<title><?= $title ?></title>

<!-- Bootstrap -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
Expand Down Expand Up @@ -93,14 +94,15 @@
<input type="hidden" name="customer_id" value="<?= $customerId ?>">
<input type="hidden" name="return_url" value="<?= $returnUrl ?>">
<input type="hidden" name="custom_reference" value="<?= $customReference ?>">
<input type="hidden" name="verification_hash" value="<?= $verificationHash?>">
<input type="hidden" name="verification_hash" value="<?= $verificationHash ?>">

<div id="newCardInfo">
<div class="form-group">
<label>Description</label>
<div class="input-group">
<input type="text" name="card_description" id="inputCardDescription" class="form-control" placeholder="Card description"
value="<?=$_POST['card_description'] ?? ''?>"
<input type="text" name="card_description" id="inputCardDescription" class="form-control"
placeholder="Card description"
value="<?= $_POST['card_description'] ?? '' ?>"
>
<div class="input-group-append">
<span class="input-group-text text-muted">
Expand All @@ -111,35 +113,43 @@
</div>
<div class="form-group">
<label>Card Number</label>
<input type="tel" name="card_number" id="inputCardNumber" class="form-control" required placeholder="1234 1234 1234 1234"
<input type="tel" name="card_number" id="inputCardNumber" class="form-control" required
placeholder="1234 1234 1234 1234"
data-supported-cards="visa,mastercard,amex,jcb"
value="<?=$_POST['card_number'] ?? ''?>"
value="<?= $_POST['card_number'] ?? '' ?>"
>
</div>
<div class="row">
<div class="form-group col-md-6 col-sm-6">
<label>Expiry Date</label>
<input type="text" name="card_expired" id="inputCardExpiry" class="form-control" required
placeholder="MM / YY"
value="<?=$_POST['card_expiry_date'] ?? ''?>"
value="<?= $_POST['card_expiry_date'] ?? '' ?>"
>
</div>
<div class="form-group col-md-6 col-sm-6">
<label>CVV Number</label>
<input type="password" name="card_cvv" id="inputCardCVV" class="form-control" required placeholder="CVN" >
<input type="password" name="card_cvv" id="inputCardCVV" class="form-control" required
placeholder="CVN">
</div>
</div>
</div>
<p class="validation"></p>
<button type="submit" id="btnSaveCC" class="btn btn-primary">Save Changes</button>
<button type="button" data-href="<?=$_POST['payment_method_url'] ?? ''?>" id="btnCancel" class="btn btn-secondary">Cancel</button>
<button type="button" data-href="<?= $_POST['payment_method_url'] ?? '' ?>" id="btnCancel"
class="btn btn-secondary">Cancel
</button>
</form>

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"
integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"
integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
crossorigin="anonymous"></script>

<script type="text/javascript" src="https://js.xendit.co/v1/xendit.min.js"></script>
<script src="/assets/js/jquery.payment.js"></script>
Expand Down
15 changes: 13 additions & 2 deletions modules/gateways/xendit/lib/ActionBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,17 @@ protected function generateExternalId(int $invoiceId, bool $retry = false): stri
{
$config = $this->getXenditConfig();
$externalPrefix = !empty($config["xenditExternalPrefix"]) ? $config["xenditExternalPrefix"] : "WHMCS-Xendit";
return !$retry ? sprintf("%s-%s", $externalPrefix, $invoiceId) : sprintf("%s-%s-%s", $externalPrefix, uniqid(), $invoiceId);
return !$retry ? sprintf(
"%s-%s",
$externalPrefix,
$invoiceId
)
: sprintf(
"%s-%s-%s",
$externalPrefix,
uniqid(),
$invoiceId
);
}

/**
Expand Down Expand Up @@ -186,7 +196,8 @@ public function updateTransactions($transactions, array $attributes = []): bool
*/
public function extractPaidAmount($xenditTotal, $whmcsTotal): float
{
return $xenditTotal - $whmcsTotal > 0 && $xenditTotal - $whmcsTotal < 1 ? (float)$whmcsTotal : (float)$xenditTotal;
$decimalAmount = $xenditTotal - $whmcsTotal ;
return $decimalAmount > 0 && $decimalAmount < 1 ? (float)$whmcsTotal : (float)$xenditTotal;
}

/**
Expand Down
12 changes: 0 additions & 12 deletions modules/gateways/xendit/lib/CreditCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,6 @@ public function generateCCPaymentRequest(array $params = [], int $auth_id = null
return $payload;
}

/**
* @return false|string
* @throws \Exception
*/
public function getCardSetting()
{
$ccSettings = $this->xenditRequest->getCCSettings();
$midSettings = $this->xenditRequest->getMIDSettings();
$ccSettings['supported_card_brands'] = !empty($midSettings['supported_card_brands']) ? $midSettings['supported_card_brands'] : array();
return $ccSettings;
}

/**
* @param string $verificationHash
* @param array $params
Expand Down
15 changes: 14 additions & 1 deletion modules/gateways/xendit/lib/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,19 @@ protected function isViewInvoicePage(): bool
return ltrim($_SERVER["SCRIPT_NAME"], "/") == "viewinvoice.php";
}

/**
* @param string $systemUrl
* @return string
*/
public function getCallbackUrl(string $systemUrl): string
{
return sprintf(
'%s/modules/gateways/callback/%s.php',
$systemUrl,
$this->getDomainName()
);
}

/**
* @param array $params
* @param string $invoiceUrl
Expand Down Expand Up @@ -124,7 +137,7 @@ protected function generateFormParam(array $params, string $invoiceUrl): string
$postfields['postcode'] = $params['clientdetails']['postcode'];
$postfields['country'] = $params['clientdetails']['country'];
$postfields['phone'] = $params['clientdetails']['phonenumber'];
$postfields['callback_url'] = $params['systemurl'] . '/modules/gateways/callback/' . $this->getDomainName() . '.php';
$postfields['callback_url'] = $this->getCallbackUrl($params['systemurl']);
$postfields['return_url'] = $params['returnurl'];

$htmlOutput = '<form id="frm-xendit" method="post" action="' . $invoiceUrl . '">';
Expand Down
5 changes: 4 additions & 1 deletion modules/gateways/xendit/tests/WHMCSModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ public function testCallbackPaidTotal()

foreach ($this->totalDataProvider() as $total) {
$this->assertIsFloat($actionBase->extractPaidAmount($total["xenditTotal"], $total["whmcsTotal"]));
$this->assertEquals($total["expectTotal"], $actionBase->extractPaidAmount($total["xenditTotal"], $total["whmcsTotal"]));
$this->assertEquals(
$total["expectTotal"],
$actionBase->extractPaidAmount($total["xenditTotal"], $total["whmcsTotal"])
);
}
}
}

0 comments on commit 7a5d107

Please sign in to comment.