-
-
Notifications
You must be signed in to change notification settings - Fork 241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bexley] Access paysuite integration #5369
Draft
chrismytton
wants to merge
1
commit into
bexley-ww-garden-subscription
Choose a base branch
from
access-paysuite-integration
base: bexley-ww-garden-subscription
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,55 @@ | ||
#!/usr/bin/env perl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
BEGIN { # set all the paths to the perl code | ||
use File::Basename qw(dirname); | ||
use File::Spec; | ||
my $d = dirname(File::Spec->rel2abs($0)); | ||
require "$d/../setenv.pl"; | ||
} | ||
|
||
use Integrations::AccessPaySuite; | ||
|
||
my $client = Integrations::AccessPaySuite->new( | ||
config => { | ||
endpoint => 'https://playpen.accesspaysuite.com', | ||
client_code => 'APIRTM', | ||
api_key => $ENV{ACCESS_PAYSUITE_API_KEY} | ||
} | ||
); | ||
|
||
# Create a customer | ||
my $customer = $client->create_customer({ | ||
customerRef => '[email protected]', | ||
email => '[email protected]', | ||
title => 'Mr', | ||
firstName => 'John', | ||
surname => 'Doe', | ||
postCode => 'SE1 1AA', | ||
accountNumber => '12345678', | ||
bankSortCode => '123456', | ||
accountHolderName => 'John Doe', | ||
line1 => '123 Main St', | ||
line2 => 'Apt 1', | ||
}); | ||
use Devel::Dwarn; | ||
::Dwarn($customer); | ||
|
||
# Set up a direct debit | ||
my $contract = $client->create_contract($customer->{Id}, { | ||
scheduleId => '38491b98-e3dd-45c1-80e7-e44941e481c6', | ||
start => '2025-03-01T00:00:00.000', | ||
isGiftAid => 0, | ||
terminationType => "Until further notice", | ||
atTheEnd => "Switch to further notice", | ||
paymentMonthInYear => 3, | ||
additionalReference => 'BEXLEY GGW', | ||
paymentDayInMonth => 28, | ||
amount => 50.00, | ||
}); | ||
::Dwarn($contract); | ||
|
||
print "Customer ID: $customer->{Id}\n"; | ||
print "Contract ID: $contract->{Id}\n"; |
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,156 @@ | ||
package FixMyStreet::App::Form::Waste::BankDetails; | ||
|
||
use utf8; | ||
use HTML::FormHandler::Moose; | ||
use mySociety::PostcodeUtil; | ||
extends 'FixMyStreet::App::Form::Waste'; | ||
|
||
has_field name_title => ( | ||
type => 'Text', | ||
required => 1, | ||
label => 'Title (e.g. Mr, Mrs, Ms, Dr, etc.)', | ||
); | ||
|
||
has_field first_name => ( | ||
type => 'Text', | ||
required => 1, | ||
label => 'First name', | ||
validate_method => sub { | ||
my $self = shift; | ||
return unless $self->value; | ||
$self->add_error('First name must be 255 characters or less') if length($self->value) > 255; | ||
}, | ||
); | ||
|
||
has_field surname => ( | ||
type => 'Text', | ||
required => 1, | ||
label => 'Surname', | ||
validate_method => sub { | ||
my $self = shift; | ||
return unless $self->value; | ||
$self->add_error('Surname must be 255 characters or less') if length($self->value) > 255; | ||
}, | ||
); | ||
|
||
has_field address1 => ( | ||
type => 'Text', | ||
required => 1, | ||
label => 'Address line 1', | ||
validate_method => sub { | ||
my $self = shift; | ||
return unless $self->value; | ||
$self->add_error('Address line 1 must be 50 characters or less') | ||
if length($self->value) > 50; | ||
}, | ||
); | ||
|
||
has_field address2 => ( | ||
type => 'Text', | ||
required => 1, | ||
label => 'Address line 2', | ||
validate_method => sub { | ||
my $self = shift; | ||
return unless $self->value; | ||
$self->add_error('Address line 2 must be 30 characters or less') | ||
if length($self->value) > 30; | ||
}, | ||
); | ||
|
||
has_field address3 => ( | ||
type => 'Text', | ||
required => 0, | ||
label => 'Address line 3', | ||
validate_method => sub { | ||
my $self = shift; | ||
return unless $self->value; | ||
$self->add_error('Address line 3 must be 30 characters or less') | ||
if length($self->value) > 30; | ||
}, | ||
); | ||
|
||
has_field address4 => ( | ||
type => 'Text', | ||
required => 0, | ||
label => 'Address line 4', | ||
validate_method => sub { | ||
my $self = shift; | ||
return unless $self->value; | ||
$self->add_error('Address line 4 must be 30 characters or less') | ||
if length($self->value) > 30; | ||
}, | ||
); | ||
|
||
has_field post_code => ( | ||
type => 'Text', | ||
required => 1, | ||
label => 'Post code', | ||
validate_method => sub { | ||
my $self = shift; | ||
return unless $self->value; | ||
$self->add_error('Please enter a valid postcode') | ||
unless mySociety::PostcodeUtil::is_valid_postcode($self->value); | ||
}, | ||
); | ||
|
||
has_field account_holder => ( | ||
type => 'Text', | ||
required => 1, | ||
label => 'Name of account holder', | ||
validate_method => sub { | ||
my $self = shift; | ||
return unless $self->value; | ||
my $value = $self->value; | ||
# Remove any special characters, keeping only alphanumeric and spaces | ||
$value =~ s/[^a-zA-Z0-9 ]//g; | ||
$self->add_error('Account holder name must be 18 characters or less') | ||
if length($value) > 18; | ||
# Update the value to the cleaned version | ||
$self->value($value); | ||
}, | ||
); | ||
|
||
has_field account_number => ( | ||
type => 'Text', | ||
required => 1, | ||
label => 'Account number', | ||
validate_method => sub { | ||
my $self = shift; | ||
return unless $self->value; | ||
$self->add_error('Please enter a valid 8 digit account number') | ||
unless $self->value =~ /^\d{8}$/; | ||
}, | ||
); | ||
|
||
has_field sort_code => ( | ||
type => 'Text', | ||
required => 1, | ||
label => 'Sort code', | ||
validate_method => sub { | ||
my $self = shift; | ||
return unless $self->value; | ||
my $sort_code = $self->value; | ||
$sort_code =~ s/[^0-9]//g; | ||
$self->add_error('Please enter a valid 6 digit sort code') | ||
unless $sort_code =~ /^\d{6}$/; | ||
}, | ||
); | ||
|
||
# Create a dedicated page for entering bank details. | ||
has_page bank_details => ( | ||
title => 'Enter Your Bank Details', | ||
template => 'waste/bank_details.html', | ||
fields => ['account_holder', 'account_number', 'sort_code', 'reference', 'amount', 'report_id', 'submit'], | ||
next => sub { | ||
my $form = shift; | ||
return $form->wizard_finished('process_bank_details'); | ||
}, | ||
); | ||
Comment on lines
+139
to
+148
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if this is even needed? |
||
|
||
has_field submit => ( | ||
type => 'Submit', | ||
value => 'Set up Direct Debit', | ||
element_attr => { class => 'govuk-button' }, | ||
); | ||
|
||
1; |
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 |
---|---|---|
|
@@ -8,7 +8,8 @@ | |
|
||
use Moo::Role; | ||
with 'FixMyStreet::Roles::Cobrand::SCP', | ||
'FixMyStreet::Roles::Cobrand::Paye'; | ||
'FixMyStreet::Roles::Cobrand::Paye', | ||
'FixMyStreet::Roles::Cobrand::AccessPaySuite'; | ||
|
||
sub garden_service_name { 'garden waste collection service' } | ||
|
||
|
@@ -37,4 +38,47 @@ | |
return $p->id; | ||
} | ||
|
||
sub waste_payment_ref_council_code { "BEX" } | ||
|
||
sub direct_debit_collection_method { 'internal' } | ||
|
||
sub setup_direct_debit { | ||
my ($self, $form) = @_; | ||
my $c = $self->{c}; | ||
my $data = $form->value; | ||
|
||
my $i = $self->get_dd_integration; | ||
my $customer = $i->create_customer({ | ||
customerRef => $data->{email}, | ||
email => $data->{email}, | ||
title => $data->{name_title}, | ||
firstName => $data->{first_name}, | ||
surname => $data->{surname}, | ||
postCode => $data->{post_code}, | ||
accountNumber => $data->{account_number}, | ||
bankSortCode => $data->{sort_code}, | ||
accountHolderName => $data->{account_holder}, | ||
line1 => $data->{address1}, | ||
line2 => $data->{address2}, | ||
line3 => $data->{address3}, | ||
line4 => $data->{address4}, | ||
}); | ||
my $contract = $i->create_contract($customer->{Id}, { | ||
scheduleId => '38491b98-e3dd-45c1-80e7-e44941e481c6', | ||
start => '2025-03-01T00:00:00.000', | ||
isGiftAid => 0, | ||
terminationType => "Until further notice", | ||
atTheEnd => "Switch to further notice", | ||
paymentMonthInYear => 3, | ||
paymentDayInMonth => 28, | ||
amount => 50.00, | ||
additionalReference => 'BEXLEY GGW', | ||
Comment on lines
+66
to
+75
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some of this needs to take the dynamic values from the |
||
}); | ||
|
||
::Dwarn($data); | ||
::Dwarn($customer); | ||
::Dwarn($contract); | ||
return 1; | ||
} | ||
|
||
1; |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm trying to display an extra form to gather the users details instead of redirecting them off to a portal like we do for other places, but it's not working as it should.
I think when the POST request is made for the Direct Debit details form it's picked up as a re-submission of the garden form, and so goes back to the page with the terms and conditions checkbox again, instead of submitting the Direct Debit.
I tried to alter the existing garden form to add a new page for the direct debit, but I couldn't get that working, I think in part because there are a lot of assumptions that the summary page will be the final page.
I must be missing a much easier way to do this?