aboutsummaryrefslogtreecommitdiff
path: root/Week16 Webshop/src/com/camilstaps/webshop/payment/IDeal.java
blob: 43c95bf3ac14a76f3d35d37284b7d10c74750afb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
 * Copyright (c) 2015 Camil Staps
 */
package com.camilstaps.webshop.payment;

import java.util.Scanner;

/**
 *
 * @author camilstaps
 */
public class IDeal implements PaymentMethod {
    
    private String bank, accountNr, pincode;
    private Scanner sc = new Scanner(System.in);
    
    public IDeal() {
    }
    
    public IDeal(String bank, String accountNr, String pincode) {
        this.bank = bank;
        this.accountNr = accountNr;
        this.pincode = pincode;
    }
    
    private void ensureBank() {
        if (bank != null) return;
        System.out.print("Bank: ");
        bank = sc.nextLine();
    }
    
    private void ensureAccountNr() {
        if (accountNr != null) return;
        System.out.print("Account nr: ");
        accountNr = sc.nextLine();
    }
    
    private void ensurePincode() {
        if (pincode != null) return;
        System.out.print("Pincode: ");
        pincode = sc.nextLine();
    }

    @Override
    public boolean pay(double amount) {
        ensureBank();
        ensureAccountNr();
        ensurePincode();
        System.out.println("€" + amount + " paid with iDeal: \n" + bank + " : " + accountNr + " (" + pincode + ")");
        return true;
    }
    
}