Commit 3e3cb2cd authored by sagarwani's avatar sagarwani

First Commit

parents
langcode: en
status: true
dependencies:
config:
- field.storage.profile.field_telepone_no
- profile.type.customer
module:
- telephone
id: profile.customer.field_telepone_no
field_name: field_telepone_no
entity_type: profile
bundle: customer
label: 'Telepone No'
description: ''
required: true
translatable: false
default_value: { }
default_value_callback: ''
settings: { }
field_type: telephone
langcode: en
status: true
dependencies:
module:
- profile
- telephone
id: profile.field_telepone_no
field_name: field_telepone_no
entity_type: profile
type: telephone
settings: { }
module: telephone
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
commerce_payment.commerce_payment_gateway.plugin.ipay_onsite:
type: commerce_payment_gateway_configuration
mapping:
api_key:
type: string
label: 'API key'
commerce_payment.commerce_payment_gateway.plugin.ipay_offsite_redirect:
type: commerce_payment_gateway_configuration
mapping:
redirect_method:
type: string
label: 'Redirect method'
merchant_code:
type: string
label: 'Merchant Code'
merchant_key:
type: string
label: 'Merchant Key'
name: Commerce Ipay88 Payment
type: module
description: 'Provides ipay88 payment gateway.'
package: Commerce
core: 8.x
dependencies:
- commerce:commerce
- commerce:commerce_payment
- drupal:telephone
commerce_payment_ipay.responce:
path: '/commerce_payment_ipay/responce'
defaults:
_controller: '\Drupal\commerce_payment_ipay\Controller\ResponceController::responce'
options:
no_cache: TRUE
requirements:
_access: 'TRUE'
commerce_payment_ipay.responce_backend:
path: 'commerce_payment_ipay/responce_backend'
defaults:
_controller: '\Drupal\commerce_payment_ipay\Controller\ResponceController::responce_backend'
options:
no_cache: TRUE
requirements:
_access: 'TRUE'
<?php
namespace Drupal\commerce_payment_ipay\Controller;
//use Drupal\Core\DependencyInjection\ControllerBase;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Url;
/**
* This is a dummy controller for mocking an off-site gateway.
*/
class ResponceController extends ControllerBase {
public function responce() {
if (!empty($_REQUEST)) {
$merchantcode = $_REQUEST["MerchantCode"];
$paymentid = $_REQUEST["PaymentId"];
$refno = $_REQUEST["RefNo"];
$amount = $_REQUEST["Amount"];
$ecurrency = $_REQUEST["Currency"];
$remark = $_REQUEST["Remark"];
$transid = $_REQUEST["TransId"];
$authcode = $_REQUEST["AuthCode"];
$status = $_REQUEST["Status"];
$errdesc = $_REQUEST["ErrDesc"];
$signature = $_REQUEST["Signature"];
if ($status == 1 && $errdesc == ""){
$oderId = substr($refno, 3);
$path = URL::fromUserInput('/checkout/' . $oderId . '/payment/return', ['query' => $_REQUEST])->toString();
return new RedirectResponse($path);
}
else {
\Drupal::logger('Response ipay88')->notice("<pre>" .print_r($_REQUEST, true). "</pre>");
$oderId = substr($refno, 3);
$path = URL::fromUserInput('/checkout/' . $oderId . '/payment/cancel', ['query' => $_REQUEST])->toString();
return new RedirectResponse($path);
}
}
}
public function responce_backend(){
$build = [
'#type' => 'markup',
'#markup' => $this->t('Thank you for your order!')
];
return $build;
}
}
<?php
namespace Drupal\commerce_payment_ipay\Plugin\Commerce\PaymentGateway;
use Drupal\commerce_order\Entity\OrderInterface;
use Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\OffsitePaymentGatewayBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* Provides the Off-site Redirect payment gateway.
*
* @CommercePaymentGateway(
* id = "ipay_offsite_redirect",
* label = "Ipay88 (Off-site redirect)",
* display_label = "Ipay88",
* forms = {
* "offsite-payment" = "Drupal\commerce_payment_ipay\PluginForm\OffsiteRedirect\PaymentOffsiteForm",
* },
* payment_method_types = {"credit_card"},
* credit_card_types = {
* "amex", "dinersclub", "discover", "jcb", "maestro", "mastercard", "visa",
* },
* )
*/
class OffsiteRedirect extends OffsitePaymentGatewayBase {
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [
'redirect_method' => 'post',
'merchant_code' => '',
] + parent::defaultConfiguration();
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
// A real gateway would always know which redirect method should be used,
// it's made configurable here for test purposes.
$form['redirect_method'] = [
'#type' => 'radios',
'#title' => $this->t('Redirect method'),
'#options' => [
'post' => $this->t('Redirect via POST (automatic)'),
],
'#default_value' => $this->configuration['redirect_method'],
];
$form['merchant_code'] = [
'#type' => 'textfield',
'#title' => $this->t('Merchant Code'),
'#default_value' => $this->configuration['merchant_code'],
'#required' => TRUE,
];
$form['merchant_key'] = [
'#type' => 'textfield',
'#title' => $this->t('Merchant Key'),
'#default_value' => $this->configuration['merchant_key'] ? $this->configuration['merchant_key'] : '',
'#required' => TRUE,
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
parent::submitConfigurationForm($form, $form_state);
if (!$form_state->getErrors()) {
$values = $form_state->getValue($form['#parents']);
$this->configuration['redirect_method'] = $values['redirect_method'];
$this->configuration['merchant_code'] = $values['merchant_code'];
$this->configuration['merchant_key'] = $values['merchant_key'];
}
}
/**
* {@inheritdoc}
*/
public function onReturn(OrderInterface $order, Request $request) {
// @todo Add examples of request validation.
if (!empty($_REQUEST) && $_REQUEST['Status'] == 1) {
$transid = $_REQUEST["TransId"];
$payment_storage = $this->entityTypeManager->getStorage('commerce_payment');
$payment = $payment_storage->create([
'state' => 'authorization',
'amount' => $order->getTotalPrice(),
'payment_gateway' => $this->entityId,
'order_id' => $order->id(),
'remote_id' => $transid,
'remote_state' => 1,
]);
$payment->save();
}
}
/**
* {@inheritdoc}
*/
public function onCancel(OrderInterface $order, Request $request) {
if ($_REQUEST['ErrDesc'] == 'Customer Cancel Transaction') {
drupal_set_message("Payment canceled", 'error');
}
else {
drupal_set_message("Payment Error", 'error');
drupal_set_message($_REQUEST['ErrDesc'], 'error');
}
}
}
<?php
namespace Drupal\commerce_payment_ipay\PluginForm\OffsiteRedirect;
use Drupal\commerce_payment\Exception\PaymentGatewayException;
use Drupal\commerce_payment\PluginForm\PaymentOffsiteForm as BasePaymentOffsiteForm;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
class PaymentOffsiteForm extends BasePaymentOffsiteForm {
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
/** @var \Drupal\commerce_payment\Entity\PaymentInterface $payment */
$payment = $this->entity;
/** @var \Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\OffsitePaymentGatewayInterface $payment_gateway_plugin */
$payment_gateway_plugin = $payment->getPaymentGateway()->getPlugin();
$redirect_method = $payment_gateway_plugin->getConfiguration()['redirect_method'];
$merchant_code = $payment_gateway_plugin->getConfiguration()['merchant_code'];
$merchant_key = $payment_gateway_plugin->getConfiguration()['merchant_key'];
$remove_js = ($redirect_method == 'post_manual');
if (in_array($redirect_method, ['post', 'post_manual'])) {
$redirect_url = 'https://payment.ipay88.com.my/epayment/entry.asp';
$responce_url = Url::fromRoute('commerce_payment_ipay.responce', [], ['absolute' => TRUE])->toString();
$redirect_method = 'post';
}
$order = $payment->getOrder();
$billing_profile = $order->getBillingProfile();
$address_info = $billing_profile->get('address')->getValue();
$payment_amount = $payment->getAmount()->getNumber();
$amount_source = number_format($payment_amount, 2);
$amount_source = str_replace('.', '', $amount_source);
$signature_source = $merchant_key.$merchant_code.'ORD'.$order->id().$amount_source.'MYR';
$signature = hash('sha256', $signature_source);
$data = [
'return' => $redirect_url,
'cancel' => $form['#cancel_url'],
'MerchantCode' => $merchant_code,
'PaymentId' => 2,
'RefNo' => 'ORD' . $order->id(),
'Amount' => number_format($payment_amount, 2),
'Currency' => 'MYR',
'ProdDesc' => 'JiozStudio Product',
'UserName' => $address_info[0]['given_name'] . ' ' .$address_info[0]['family_name'],
'UserEmail' => $order->getEmail(),
'UserContact' => $billing_profile->get('field_telepone_no')->getValue()[0]['value'],
'SignatureType' => 'SHA256',
'Signature' => $signature,
'ResponseURL' => $responce_url,
'BackendURL' => 'https://sample2.jiozstudio.com/commerce_payment_ipay/responce_backend',
];
$form = $this->buildRedirectForm($form, $form_state, $redirect_url, $data, $redirect_method);
if ($remove_js) {
// Disable the javascript that auto-clicks the Submit button.
unset($form['#attached']['library']);
}
return $form;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment