Skip to content

Commit

Permalink
Merge pull request #138 from andrepayone/payla-secured-direct-debit
Browse files Browse the repository at this point in the history
Payla secured direct debit
  • Loading branch information
janteuber authored Apr 26, 2023
2 parents 90541c7 + a03b43a commit 4586804
Show file tree
Hide file tree
Showing 15 changed files with 1,168 additions and 979 deletions.
Binary file added assets/icon-secured-lastschrift.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified lang/payone-woocommerce-3-de_CH.mo
Binary file not shown.
399 changes: 202 additions & 197 deletions lang/payone-woocommerce-3-de_CH.po

Large diffs are not rendered by default.

Binary file modified lang/payone-woocommerce-3-de_CH_informal.mo
Binary file not shown.
399 changes: 202 additions & 197 deletions lang/payone-woocommerce-3-de_CH_informal.po

Large diffs are not rendered by default.

Binary file modified lang/payone-woocommerce-3-de_DE.mo
Binary file not shown.
399 changes: 202 additions & 197 deletions lang/payone-woocommerce-3-de_DE.po

Large diffs are not rendered by default.

Binary file modified lang/payone-woocommerce-3-de_DE_formal.mo
Binary file not shown.
399 changes: 202 additions & 197 deletions lang/payone-woocommerce-3-de_DE_formal.po

Large diffs are not rendered by default.

386 changes: 196 additions & 190 deletions lang/payone-woocommerce-3.pot

Large diffs are not rendered by default.

76 changes: 76 additions & 0 deletions src/Payone/Gateway/SecuredDirectDebit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

namespace Payone\Gateway;

class SecuredDirectDebit extends PaylaBase {

const GATEWAY_ID = 'payone_secured_direct_debit';

protected $min_amount_validation = 10;
protected $max_amount_validation = 1500;

public function __construct() {
parent::__construct( self::GATEWAY_ID );

$this->icon = PAYONE_PLUGIN_URL . 'assets/icon-secured-lastschrift.png';
$this->method_title = 'PAYONE ' . __( 'Secured Direct Debit', 'payone-woocommerce-3' );
$this->method_description = '';
}

public function init_form_fields() {
$this->supported_countries = [
'DE' => __( 'Germany', 'woocommerce' ),
'AT' => __( 'Austria', 'woocommerce' ),
];
$this->init_common_form_fields( 'PAYONE ' . __( 'Secured Direct Debit', 'payone-woocommerce-3' ) );
$this->form_fields['countries']['default'] = [ 'DE', 'AT' ];
}

public function payment_fields() {
$environment = $this->get_mode() === 'live' ? 'p' : 't';
$snippet_token = self::PAYLA_PARTNER_ID . '_' . $this->get_merchant_id() . '_' . md5(uniqid('payone_secured_invoice', true));

include PAYONE_VIEW_PATH . '/gateway/common/checkout-form-fields.php';
include PAYONE_VIEW_PATH . '/gateway/payla/secured-direct-debit-payment-form.php';
}

public function process_payment( $order_id ) {
global $woocommerce;
$order = new \WC_Order( $order_id );

$transaction = new \Payone\Transaction\SecuredDirectDebit( $this );

$response = $transaction->execute( $order );

if ( $response->has_error() ) {
wc_add_notice( $this->get_error_message( $response ), 'error' );

$this->payla_request_failed();

return;
}

$order->set_transaction_id( $response->get( 'txid' ) );
$order->add_meta_data( '_payone_userid', $response->get( 'userid', '' ) );

$authorization_method = $transaction->get( 'request' );
$order->update_meta_data( '_authorization_method', $authorization_method );
$order->save_meta_data();
$order->save();

if ( $authorization_method === 'preauthorization' ) {
$order->update_status( 'on-hold', __( 'Waiting for payment.', 'payone-woocommerce-3' ) );
} elseif ( $authorization_method === 'authorization' ) {
$order->update_status( 'processing',
__( 'Payment is authorized and captured.', 'payone-woocommerce-3' ) );
}

wc_reduce_stock_levels( $order_id );
$woocommerce->cart->empty_cart();

return array(
'result' => 'success',
'redirect' => $this->get_return_url( $order ),
);
}
}
1 change: 1 addition & 0 deletions src/Payone/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public function init() {
\Payone\Gateway\Przelewy24::GATEWAY_ID => \Payone\Gateway\Przelewy24::class,
\Payone\Gateway\SecuredInvoice::GATEWAY_ID => \Payone\Gateway\SecuredInvoice::class,
\Payone\Gateway\SecuredInstallment::GATEWAY_ID => \Payone\Gateway\SecuredInstallment::class,
\Payone\Gateway\SecuredDirectDebit::GATEWAY_ID => \Payone\Gateway\SecuredDirectDebit::class,
];

foreach ( $gateways as $gateway ) {
Expand Down
39 changes: 39 additions & 0 deletions src/Payone/Transaction/SecuredDirectDebit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Payone\Transaction;

class SecuredDirectDebit extends Base {
/**
* @param \Payone\Gateway\GatewayBase $gateway
*/
public function __construct( $gateway ) {
parent::__construct( $gateway->get_authorization_method() );
$this->set_data_from_gateway( $gateway );

$this->set( 'clearingtype', 'fnc' );
$this->set( 'financingtype', 'PDD' );
$this->set( 'add_paydata[device_token]', $_POST['payone_secured_direct_debit_token'] );
$this->set( 'birthday', Base::convert_birthday( $_POST['payone_secured_direct_debit_birthday'] ) );
$this->set( 'iban', $_POST['payone_secured_direct_debit_iban'] );
$this->set( 'businessrelation', 'b2c' );
}

/**
* @param \WC_Order $order
*
* @return \Payone\Payone\Api\Response
*/
public function execute( \WC_Order $order ) {
$this->add_article_list_to_transaction( $order );
$this->set_reference( $order );
$this->set( 'amount', $order->get_total() * 100 );
$this->set( 'currency', strtoupper( $order->get_currency() ) );
$this->set_personal_data_from_order( $order );
$this->set_shipping_data_from_order( $order );
$this->set_customer_ip_from_order( $order );

$this->set( 'bankaccountholder', $this->get( 'firstname' ) . ' ' . $this->get( 'lastname' ) );

return $this->submit();
}
}
2 changes: 1 addition & 1 deletion views/gateway/payla/_disclaimer.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<p style="margin-top:15px">
<?php _e( 'By placing this order, I agree to the <a href="https://legal.paylater.payone.com/en/terms-of-payment.html" target="_blank" rel="noopener">supplementary payment terms and the risk assessment</a> for the selected payment method. I am aware of the <a href="https://legal.paylater.payone.com/en/data-protection-payments.html" target="_blank" rel="noopener">additional data protection</a> notice.', 'payone-woocommerce-3' ); ?>
<?php _e( 'By placing this order, I agree to the <a href="https://legal.paylater.payone.com/en/terms-of-payment.html" target="_blank">supplementary payment terms</a> and the performance of a risk assessment for the selected payment method. I am aware of the <a href="https://legal.paylater.payone.com/en/data-protection-payments.html" target="_blank">supplementary data protection notice</a>.', 'payone-woocommerce-3' ); ?>
</p>
47 changes: 47 additions & 0 deletions views/gateway/payla/secured-direct-debit-payment-form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<p>
<?php echo nl2br( $this->get_option( 'description' ) ); ?>
</p>
<script id="paylaDcs" type="text/javascript" src="https://d.payla.io/dcs/<?php echo esc_attr(self::PAYLA_PARTNER_ID); ?>/<?php echo esc_attr($this->get_merchant_id()); ?>/dcs.js"></script>
<script>
var paylaDcsT = paylaDcs.init("<?php echo $environment; ?>", "<?php echo $snippet_token; ?>");

function payone_checkout_clicked_<?php echo \Payone\Gateway\SecuredDirectDebit::GATEWAY_ID; ?>() {
var messages = '';

if ( jQuery('#payone_secured_direct_debit_birthday').val() === '' ) {
messages += '<?php _e( 'Please enter your birthday!', 'payone-woocommerce-3' ); ?>';
}
if ( ! payone_valid_iban( jQuery('#payone_secured_direct_debit_iban').val() ) ) {
messages += '<?php _e( 'Please enter a valid IBAN!', 'payone-woocommerce-3' ); ?><br>';
}

jQuery('#payoneSecuredDirectDebitErrorOutput').html('<strong style="color:red">' + messages + '</strong>');

return messages.length === 0;
}
</script>

<link id="paylaDcsCss" type="text/css" rel="stylesheet" href="https://d.payla.io/dcs/dcs.css?st=<?php echo esc_url($snippet_token); ?>&pi=<?php echo esc_url(self::PAYLA_PARTNER_ID); ?>&psi=<?php echo esc_url($this->get_merchant_id()); ?>&e=<?php echo esc_url($environment); ?>">

<input type="hidden" name="payone_secured_direct_debit_token" value="<?php echo esc_attr($snippet_token); ?>">
<fieldset>
<p class="form-row form-row-full validate-required" id="payone_secured_direct_debit_birthday_field">
<label for="payone_secured_direct_debit_birthday">
<?php _e( 'Birthday', 'payone-woocommerce-3' ); ?>
</label>
<span class="woocommerce-input-wrapper">
<input type="date" class="input-text " name="payone_secured_direct_debit_birthday" id="payone_secured_direct_debit_birthday">
</span>
</p>
<p class="form-row form-row-full validate-required" id="payone_secured_direct_debit_iban_field">
<label for="payone_secured_direct_debit_birthday">
<?php _e( 'IBAN', 'payone-woocommerce-3' ); ?>
</label>
<span class="woocommerce-input-wrapper">
<input type="text" class="input-text " name="payone_secured_direct_debit_iban" id="payone_secured_direct_debit_iban">
</span>
</p>
</fieldset>

<?php include( '_disclaimer.php' ); ?>
<div id="payoneSecuredDirectDebitErrorOutput"></div>

0 comments on commit 4586804

Please sign in to comment.