Skip to content

Commit

Permalink
Merge pull request #29 from buckaroo-it/develop
Browse files Browse the repository at this point in the history
v1.16.0 Release
  • Loading branch information
serpentscode authored Mar 1, 2023
2 parents 1e30fed + 062f526 commit 7da52d2
Show file tree
Hide file tree
Showing 27 changed files with 254 additions and 144 deletions.
3 changes: 3 additions & 0 deletions BuckarooPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,9 @@ protected function getAttributeColumns()
(object)[ 'table' => 's_user_attributes', 'column' => 'buckaroo_user_identification', 'type' => 'string',
'data' => [ 'displayInBackend' => true, 'label' => 'IDENT', 'supportText' => 'Customer Identification', 'helpText' => 'Needed to do Afterpay payments' ]
],
(object)[ 'table' => 's_user_attributes', 'column' => 'buckaroo_user_gender', 'type' => 'string',
'data' => [ 'displayInBackend' => true, 'label' => 'Gender', 'supportText' => 'Customer Gender', 'helpText' => 'Needed for some payment methods' ]
],
(object)[ 'table' => 's_core_countries_states_attributes', 'column' => 'buckaroo_payment_paypal_code', 'type' => 'string',
'data' => [ 'displayInBackend' => true, 'label' => 'PayPal Code', 'supportText' => 'State Code for PayPal', 'helpText' => 'Needed when ordering with PayPal' ]
]
Expand Down
24 changes: 24 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Contribution Guidelines

### Repository setup:
- Fork the repository to your account.
- More details about [how to fork a repo](https://docs.github.com/en/github/getting-started-with-github/fork-a-repo) can be found [here](https://docs.github.com/en/github/getting-started-with-github/fork-a-repo).

### Making changes:
- Create a branch from the develop branch (if there is a develop branch).
- Name of the branch shoul be something like: `feature/GITHUB-ISSUE-ID-slug` (eg: `feature/50-configprovider-update`)
- Your code changes should follow the Shopware coding standard.
- Including unit tests is encouraged.

### Pull Request:
- Open the PR to develop branch.
- If there is no issue referenced, add a description about the problem and the way it is being solved.
- Allow edits from maintainers.


### Contribution to refactoring:
- The branch should be created from refactoring.
- Code changes should follow the Shopware coding standard.
- Include unit tests.
- Open the Pull Request.
- Check that Git workflows checks have passed.
8 changes: 6 additions & 2 deletions Components/Base/AbstractPaymentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ protected function getAdditionalUser()
protected function getAdditionalUserGender()
{
$user = $this->getAdditionalUser();
$gender = Gender::MAN;
$gender = Gender::UNKNOWN;

if( $user && !empty($user['salutation']) ) {
$salutation = $user['salutation'];
Expand Down Expand Up @@ -385,7 +385,11 @@ protected function convertSalutationToGender($salutation){
return Gender::WOMAN;
}

return Gender::MAN;
if (empty($salutation)) {
return Gender::UNKNOWN;
}

return Gender::MALE;
}

/**
Expand Down
19 changes: 0 additions & 19 deletions Components/Base/SimplePaymentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,6 @@ public function payAction()
{
SimpleLog::log(__METHOD__ . "|4|");

$this->removeArticlesStock();
$transaction->setNeedsRestock(1);

$transactionManager->save($transaction);
return $this->redirect($response->getRedirectUrl());
}

Expand Down Expand Up @@ -348,10 +344,6 @@ public function payEncryptedAction()
// redirect to Buckaroo
if( $response->hasRedirect() )
{
$this->removeArticlesStock();
$transaction->setNeedsRestock(1);

$transactionManager->save($transaction);
return $this->redirect($response->getRedirectUrl());
}

Expand Down Expand Up @@ -702,17 +694,6 @@ public function refundPushAction($data = false)
return $this->sendResponse('Refund Push - OK');
}

public function removeArticlesStock()
{
$articalIds = $this->getBasketArticleIds();

foreach ($articalIds as $article) {
$query = sprintf("UPDATE s_articles_details set instock = instock - %d WHERE id = %d", (int)$article['quantity'], (int)$article['article_details_id'] );
Shopware()->Db()->executeQuery($query);
}

}

public function addArticlesStock()
{
$articalIds = $this->getBasketArticleIds();
Expand Down
2 changes: 2 additions & 0 deletions Components/Constants/Gender.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ class Gender

const MALE = 1;
const FEMALE = 2;
const THEY = 0;
const UNKNOWN = 9;
}
9 changes: 5 additions & 4 deletions Components/ExtraFieldsLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function load()
throw new Exception(__CLASS__ . " has no method '" . $method . "'");
}

$this->collectData[$entity] = $this->{$method}($keys, $this->collectData['lists']);
$this->collectData[$entity] = $this->{$method}($this->collectData['lists'], $keys);
}

return $this->collectData;
Expand Down Expand Up @@ -118,9 +118,10 @@ protected function getCurrentUser()
* @param array $keys
* @return array
*/
protected function loadUser($keys = [], &$lists)
protected function loadUser(&$lists, $keys = [])
{
$keys['id'] = 'id';
$keys['salutation'] = 'salutation';
$data = [];


Expand Down Expand Up @@ -203,7 +204,7 @@ protected function loadUser($keys = [], &$lists)
* @param array $keys
* @return array
*/
protected function loadBilling($keys = [], &$lists)
protected function loadBilling(&$lists, $keys = [])
{
$keys['id'] = 'id';
$data = [];
Expand Down Expand Up @@ -253,7 +254,7 @@ protected function loadBilling($keys = [], &$lists)
* @param array $keys
* @return array
*/
protected function loadShipping($keys = [], &$lists)
protected function loadShipping(&$lists, $keys = [])
{
$keys['id'] = 'id';
$data = [];
Expand Down
6 changes: 3 additions & 3 deletions Components/JsonApi/Payload/PaymentResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,19 @@ public function getData($key = null)
}

/** Implement ArrayAccess */
public function offsetSet($offset, $value)
public function offsetSet($offset, $value): void
{
$this->data[$offset] = $value;
}

/** Implement ArrayAccess */
public function offsetExists($offset)
public function offsetExists($offset) :bool
{
return isset($this->data[$offset]);
}

/** Implement ArrayAccess */
public function offsetUnset($offset)
public function offsetUnset($offset): void
{
unset($this->data[$offset]);
}
Expand Down
6 changes: 3 additions & 3 deletions Components/JsonApi/Payload/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function __construct($data = [])
}

/** Implement ArrayAccess */
public function offsetSet($offset, $value)
public function offsetSet($offset, $value) : void
{
if (is_null($offset)) {
$this->data[] = $value;
Expand All @@ -35,13 +35,13 @@ public function offsetSet($offset, $value)
}

/** Implement ArrayAccess */
public function offsetExists($offset)
public function offsetExists($offset): bool
{
return isset($this->data[$offset]);
}

/** Implement ArrayAccess */
public function offsetUnset($offset)
public function offsetUnset($offset): void
{
unset($this->data[$offset]);
}
Expand Down
6 changes: 3 additions & 3 deletions Components/JsonApi/Payload/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ public function __construct($data, $curlInfo = [], $headers = [])
}

/** Implement ArrayAccess */
public function offsetSet($offset, $value)
public function offsetSet($offset, $value): void
{
throw new Exception("Can't set a value of a Response");
}

/** Implement ArrayAccess */
public function offsetExists($offset)
public function offsetExists($offset): bool
{
return isset($this->data[$offset]);
}

/** Implement ArrayAccess */
public function offsetUnset($offset)
public function offsetUnset($offset): void
{
unset($this->data[$offset]);
}
Expand Down
3 changes: 2 additions & 1 deletion Components/SessionCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public static function sessionToUser($data)
'buckaroo_payment_iban',
'buckaroo_payment_coc',
'buckaroo_payment_vat_num',
'buckaroo_user_identification'
'buckaroo_user_identification',
'buckaroo_user_gender'
];

foreach( $toCamelCase as $key )
Expand Down
3 changes: 0 additions & 3 deletions Controllers/Frontend/BuckarooAfterpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ protected function fillRequest(AbstractPaymentMethod $paymentMethod, Request $re
* Title Type Required Description
* =====================================================================================================================================
* BillingTitle  string Title of the billing customer.
* BillingGender  decimal Gender of the billing customer. Male (1) Female (2) Not required in case of B2B.
* BillingInitials  string Required Initials of the billing customer.
* BillingLastNamePrefix  string Last name prefix of the billing customer.
* BillingLastName  string Required Last name of the billing customer.
Expand Down Expand Up @@ -242,7 +241,6 @@ protected function fillRequest(AbstractPaymentMethod $paymentMethod, Request $re
$billingStreet = $this::setAdditionalAddressFields($billing);

$request->setServiceParameter('BillingTitle', '');
$request->setServiceParameter('BillingGender', $this->getAdditionalUserGender());
$request->setServiceParameter('BillingInitials', $billing['firstname']);
$request->setServiceParameter('BillingLastNamePrefix', '');
$request->setServiceParameter('BillingLastName', $billing['lastname']);
Expand Down Expand Up @@ -273,7 +271,6 @@ protected function fillRequest(AbstractPaymentMethod $paymentMethod, Request $re
$shippingStreet = $this::setAdditionalAddressFields($shipping);

$request->setServiceParameter('ShippingTitle', '');
$request->setServiceParameter('ShippingGender', $this->getAdditionalUserGender());
$request->setServiceParameter('ShippingInitials', $shipping['firstname']);
$request->setServiceParameter('ShippingLastNamePrefix', '');
$request->setServiceParameter('ShippingLastName', $shipping['lastname']);
Expand Down
5 changes: 0 additions & 5 deletions Controllers/Frontend/BuckarooAfterpayNew.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,9 @@ protected function addBillingCustomerParameters($request, $birthDay, $user, $pay
}

$billingStreet = $this::setAdditionalAddressFields($billing);
$salutation = ($this->getAdditionalUserGender() == '1') ? 'Mr' : 'Mrs';

if(in_array($billingCountryIso, ["NL", "BE"])){
// Netherlands and Belgium required fields:
$request->setServiceParameter('Salutation', $salutation, 'BillingCustomer');
$request->setServiceParameter('BirthDate', $birthDay, 'BillingCustomer');

if($billingCountryIso == "NL"){
Expand Down Expand Up @@ -356,11 +354,8 @@ protected function addShippingCustomerParameters($request, $birthDay, $user, $pa
$shippingCountryIso = empty($shippingCountry) ? '' : $shippingCountry->getIso();
$shippingStreet = $this::setAdditionalAddressFields($shipping);

$salutation = ($this->getAdditionalUserGender() == '1') ? 'Mr' : 'Mrs';

if(in_array($shippingCountryIso, ["NL", "BE"])){
// Netherlands and Belgium required fields:
$request->setServiceParameter('Salutation', $salutation, 'ShippingCustomer');
$request->setServiceParameter('BirthDate', $birthDay, 'ShippingCustomer');

$typeDutchPhone = $this->getTypeDutchPhoneNumber($shipping['phone']);
Expand Down
19 changes: 18 additions & 1 deletion Controllers/Frontend/BuckarooBillink.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ protected function addBillingCustomerParameters($request, $birthDay, $user, $pay
if (!empty($this->container->get('session')->sOrderVariables['sUserData']['additional']['extra']['billink']['buckaroo_payment_vat_num'])) {
$billing['buckaroo_payment_vat_num'] = $this->container->get('session')->sOrderVariables['sUserData']['additional']['extra']['billink']['buckaroo_payment_vat_num'];
}

if (!empty($this->container->get('session')->sOrderVariables['sUserData']['additional']['extra']['billink']['buckaroo_user_gender'])) {
$user['buckaroo_user_gender'] = $this->container->get('session')->sOrderVariables['sUserData']['additional']['extra']['billink']['buckaroo_user_gender'];
}

$billingCountry = $this->container->get('models')->getRepository('Shopware\Models\Country\Country')->find($billing['countryId']);
$billingCountryIso = empty($billingCountry) ? '' : $billingCountry->getIso();
Expand All @@ -236,7 +240,20 @@ protected function addBillingCustomerParameters($request, $birthDay, $user, $pay
}

$billingStreet = $this::setAdditionalAddressFields($billing);
$salutation = ($this->getAdditionalUserGender() == '1') ? 'Male' : 'Female';
switch ($user['buckaroo_user_gender']) {
case 0:
$salutation = 'Unknown';
break;
case 1:
$salutation = 'Male';
break;
case 2:
$salutation = 'Female';
break;
case 9:
$salutation = 'Unknown';
break;
}

$request->setServiceParameter('Salutation', $salutation, 'BillingCustomer');

Expand Down
3 changes: 0 additions & 3 deletions Controllers/Frontend/BuckarooKlarna.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,12 @@ protected function setMainServiceParameters($request, $billing, $klarna, $user)
$billingCountry = $this->container->get('models')->getRepository('Shopware\Models\Country\Country')->find($billing['countryId']);
$billingCountryIso = empty($billingCountry) ? '' : $billingCountry->getIso();
$billingCountryName = empty($billingCountry) ? '' : ucfirst(strtolower($billingCountry->getIsoName()));
$billingGender = $this->convertSalutationToGender($billing['salutation']);
$birthDay = !empty($user['birthday']) ? DateTime::createFromFormat('Y-m-d', $user['birthday'])->format('dmY') : '';

$request->setServiceParameter('OperatingCountry', $billingCountryIso); // Required
$request->setServiceParameter('Pno', $birthDay); // birthdate DDMMYYYY // Required
$request->setServiceParameter('ShippingSameAsBilling', $this->isShippingSameAsBilling() ? 'true' : 'false');
// $request->setServiceParameter('Encoding', $billingCountryName);
$request->setServiceParameter('Gender', $billingGender);

}

/*
Expand Down
2 changes: 1 addition & 1 deletion PaymentMethods/AfterPayAcceptgiro.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AfterPayAcceptgiro extends AbstractPaymentMethod
/**
* User friendly payment name
*/
const DESCRIPTION = 'AfterPay Eenmalige Machtiging';
const DESCRIPTION = 'Riverty | AfterPay Eenmalige Machtiging';

/**
* Position
Expand Down
2 changes: 1 addition & 1 deletion PaymentMethods/AfterPayB2BAcceptgiro.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AfterPayB2BAcceptgiro extends AbstractPaymentMethod
/**
* User friendly payment name
*/
const DESCRIPTION = 'AfterPay Eenmalige Machtiging B2B';
const DESCRIPTION = 'Riverty | AfterPay Eenmalige Machtiging B2B';

/**
* Position
Expand Down
2 changes: 1 addition & 1 deletion PaymentMethods/AfterPayB2BDigiAccept.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AfterPayB2BDigiAccept extends AbstractPaymentMethod
/**
* User friendly payment name
*/
const DESCRIPTION = 'AfterPay Digitale Factuur B2B';
const DESCRIPTION = 'Riverty | AfterPay Digitale Factuur B2B';

/**
* Position
Expand Down
2 changes: 1 addition & 1 deletion PaymentMethods/AfterPayDigiAccept.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AfterPayDigiAccept extends AbstractPaymentMethod
/**
* User friendly payment name
*/
const DESCRIPTION = 'AfterPay Digitale Factuur';
const DESCRIPTION = 'Riverty | AfterPay Digitale Factuur';

/**
* Position
Expand Down
2 changes: 1 addition & 1 deletion PaymentMethods/AfterPayNew.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AfterPayNew extends AbstractPaymentMethod
/**
* User friendly payment name
*/
const DESCRIPTION = 'AfterPay';
const DESCRIPTION = 'Riverty | AfterPay';

/**
* Position
Expand Down
Loading

0 comments on commit 7da52d2

Please sign in to comment.