Skip to content

Instantly share code, notes, and snippets.

@sironekotoro
Created June 26, 2021 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sironekotoro/b93ff9fd6db3220d61b5a81d6140516f to your computer and use it in GitHub Desktop.
Save sironekotoro/b93ff9fd6db3220d61b5a81d6140516f to your computer and use it in GitHub Desktop.
PayPay銀行と三菱UFJ銀行の手数料計算例
#!/usr/bin/env perl
package Mufj;
use strict;
use warnings;
sub new {
my $class = shift;
my $self = bless { code => '0009' }, $class;
return $self;
}
# https://bizstation.bk.mufg.jp/service/ryoukin.html
sub fee {
my $self = shift;
my %hash = @_;
# 同一行で
if ( ( $self->{code} eq $hash{to}->{code} )
&& ( $hash{amount} < 30_000 ) )
{
return 110;
}
elsif (( $self->{code} eq $hash{to}->{code} )
&& ( $hash{amount} >= 30_000 ) )
{
return 330;
}
elsif (( $self->{code} ne $hash{to}->{code} )
&& ( $hash{amount} < 30_000 ) )
{
return 550;
}
elsif (( $self->{code} ne $hash{to}->{code} )
&& ( $hash{amount} >= 30_000 ) )
{
return 770;
}
}
1;
package Paypay;
use strict;
use warnings;
sub new {
my $class = shift;
# my %hash = @_;
my $self = bless { code => '0033' }, $class;
return $self;
}
sub fee {
my $self = shift;
my %hash = @_;
if ( $self->{code} eq $hash{to}->{code} ) {
return 0;
}
elsif ( $hash{amount} < 30000 ) {
return 176;
}
elsif ( $hash{amount} >= 30000 ) {
return 275;
}
else {
die;
}
}
1;
package Bank;
use strict;
use warnings;
my %BANK_MAP = (
'0033' => Paypay->new(),
'0009' => Mufj->new(),
);
sub new {
my $class = shift;
my %hash = @_;
$hash{bank} = $BANK_MAP{ $hash{code} };
my $self = bless \%hash, $class;
return $self;
}
sub send {
my $self = shift;
my %hash = @_;
$self->{to} = $hash{to};
$self->{amount} = $hash{amount};
return $self;
}
sub fee {
my $self = shift;
# あれ?sendに移せる?
my $bank = $self->{bank};
return $bank->fee( to => $self->{to}, amount => $self->{amount} );
}
package main;
my $paypay1 = Bank->new( code => '0033' );
my $paypay2 = Bank->new( code => '0033' );
my $mufj1 = Bank->new( code => '0009' );
my $mufj2 = Bank->new( code => '0009' );
$paypay1->send( to => $paypay2, amount => 29_999 );
print $paypay1->fee(), "\n";
$paypay2->send( to => $paypay1, amount => 30_000 );
print $paypay2->fee(), "\n";
$paypay1->send( to => $mufj1, amount => 29_999 );
print $paypay1->fee(), "\n";
$paypay1->send( to => $mufj1, amount => 30_000 );
print $paypay1->fee(), "\n";
$mufj1->send( to => $mufj2, amount => 29_999 );
print $mufj1->fee(), "\n";
$mufj1->send( to => $mufj2, amount => 30_000 );
print $mufj1->fee(), "\n";
$mufj1->send( to => $paypay1, amount => 29_999 );
print $mufj1->fee(), "\n";
$mufj1->send( to => $paypay1, amount => 30_000 );
print $mufj1->fee(), "\n";
@sironekotoro
Copy link
Author

make public

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment