1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class MigratePaymentTask extends BuildTask{ |
4
|
|
|
|
5
|
|
|
protected $title = "Migrate Payments"; |
6
|
|
|
protected $description = "Update payment records from old SilverStripe payment modul. See ominpay README!"; |
7
|
|
|
|
8
|
|
|
protected $count = 0; |
9
|
|
|
|
10
|
|
|
public function run($request) { |
11
|
|
|
$query = new SQLQuery("*", "Payment"); |
|
|
|
|
12
|
|
|
foreach($query->execute() as $record){ |
13
|
|
|
if($this->migrationRequired($record)){ |
14
|
|
|
$this->migrateRecord($record); |
15
|
|
|
} |
16
|
|
|
} |
17
|
|
|
if($this->count > 0){ |
18
|
|
|
echo "Successfully migrated $this->count payments"; |
19
|
|
|
}else { |
20
|
|
|
echo "No migration needed"; |
21
|
|
|
} |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
protected function migrationRequired($record) { |
25
|
|
|
return $record['ClassName'] !== "Payment"; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
protected function migrateRecord($record) { |
29
|
|
|
$payment = new Payment($record); |
30
|
|
|
$payment->Status = "Created"; |
|
|
|
|
31
|
|
|
$payment->ClassName = "Payment"; |
32
|
|
|
$payment->MoneyAmount = $record['AmountAmount']; |
|
|
|
|
33
|
|
|
$payment->MoneyCurrency = $record['AmountCurrency']; |
|
|
|
|
34
|
|
|
|
35
|
|
|
$payment->Gateway = $this->classToGateway($record['ClassName']); |
|
|
|
|
36
|
|
|
$statusmap = array( |
37
|
|
|
'Incomplete' => 'Created', |
38
|
|
|
'Success' => 'Captured', |
39
|
|
|
'Failure' => 'Void', |
40
|
|
|
'Pending' => 'Authorized', |
41
|
|
|
'' => 'Created' |
42
|
|
|
); |
43
|
|
|
$payment->Status = $statusmap[$record['Status']]; |
|
|
|
|
44
|
|
|
$payment->write(); |
45
|
|
|
$this->count++; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
protected function classToGateway($classname) { |
49
|
|
|
$gatewaymap = array( |
50
|
|
|
"ChequePayment" => "Manual", |
51
|
|
|
"DPSPayment" => "PaymentExpress_PxPay", |
52
|
|
|
"EwayXMLPayment" => "Eway_Rapid", |
53
|
|
|
"PayPalExpressCheckoutPayment" => "PayPal_Express", |
54
|
|
|
"PaystationHostedPayment" => "Paystation_Hosted", |
55
|
|
|
"WorldpayPayment" => "WorldPay" |
56
|
|
|
); |
57
|
|
|
if(isset($gatewaymap[$classname])){ |
58
|
|
|
return $gatewaymap[$classname]; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
return $classname; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
} |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: