-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #138 from andrepayone/payla-secured-direct-debit
Payla secured direct debit
- Loading branch information
Showing
15 changed files
with
1,168 additions
and
979 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |