我目前正在为Eway做一个PHP支付网关接口,界面包括:
interface RecurringPaymentGateway
{
/**
* save subscription information to database
*
* @param Subscription $subscription
* @return bool returns true on success, false on failure
*/
public function saveToDb(Subscription $subscription);
/**
* create new subscription
*
* @param Subscription $subscription
* @return string|bool returns gateway id on success, false on failure
*/
public function createSubscription(Subscription $subscription);
/**
* update existing subscription
*
* @param Subscription $subscription
* @param Subscription $existingSubscription
* @return mixed returns true on success, false on failure
*/
public function updateSubscription(Subscription $subscription, Subscription $existingSubscription);
/**
* update only payment method for an existing subscription
*
* @param Subscription $subscription
* @return bool returns true on success, false on failure
*/
public function updateSubscriptionPayment(Subscription $subscription);
/**
* cancel existing subscription
*
* @param Subscription $subscription
* @return bool returns true on success, false on failure
*/
public function cancelSubscription(Subscription $subscription);
/**
* handles an recurring payment pingback
*
* @param array $data POST data from webhook / silent post
* @return PaymentResponse
*/
public function handleRecurringPayment($data = array());
}
我能够完成除handleRecurringPayment函数之外的所有其他功能,当处理每个定期付款时,该功能应该从Eway获得静默帖子并获得状态,如失败或成功,以便我可以更新我们这方面的信息。 / p>
现在,我已经使用Stripe API完成了这项工作,如下所示,因为它们API doc中的事件对象非常清晰,您也可以在下面看到我的代码:
public function handleRecurringPayment($data = array())
{
$response = new PaymentResponse();
// validate the incoming event
$event = StripeEvent::retrieve($data['id']);
// failed to validate event, ignore event
if ($event === false) {
$response->setStatus('invalid_event');
return $response;
}
$event_type = $event->type;
if ($event_type != 'invoice.payment_succeeded' && $event_type != 'invoice.payment_failed') {
// those are the only 2 events that we are interested in, other events can be ignored
$response->setStatus('invalid_event');
return $response;
}
/** @var Subscription $subscription */
$subscriptionId = $event->data->object->subscription;
$subscription = $this->getSubscriptionFromId($subscriptionId);
// subscription doesn't exist in database, ignore this event
if ($subscription === false || $subscription->id <= 0) {
$response->setStatus('not_found');
return $response;
}
$response->setSubscription($subscription);
if ($event_type == 'invoice.payment_failed') {
/**
* payment error
*/
$chargeId = $event->data->object->charge;
$charge = Charge::retrieve($chargeId);
$errorMessage = $charge->failure_message;
// need to return a response object
$response->setStatus('payment_failed');
$response->setMessage($errorMessage);
$subscription->error = true;
$subscription->errorMessage = $errorMessage;
// next payment attempt
$nextAttempt = $event->data->object->next_payment_attempt;
if ((int)$nextAttempt > 0) {
$nextAttemptDate = \DateTime::createFromFormat('U', (int)$nextAttempt);
$subscription->nextPayment = $nextAttemptDate;
}
$subscription->update();
$response->setSubscription($subscription);
return $response;
}
if ($event_type == 'customer.subscription.deleted') {
/**
* subscription cancelled
*/
$subscription->enabled = false;
$subscription->update();
$response->setSubscription($subscription);
$response->setStatus('cancelled');
return $response;
}
// get stripe subscription
$customer = StripeCustomer::retrieve($event->data->object->customer);
$stripeSubscription = $customer->subscriptions->retrieve($event->data->object->subscription);
// update next payment date
$nextPayment = $stripeSubscription->current_period_end;
if ((int)$nextPayment > 0) {
$nextPaymentDate = \DateTime::createFromFormat('U', (int)$nextPayment);
$subscription->nextPayment = $nextPaymentDate;
$subscription->update();
$response->setSubscription($subscription);
}
// check subscription status
if ($stripeSubscription->status == 'trialing') {
$response->setStatus('invalid_event');
return $response;
}
// update previous payment date to now
$subscription->prevPayment = new \DateTime();
$subscription->error = false;
$subscription->errorMessage = '';
$subscription->update();
$response->setSubscription($subscription);
$response->setStatus('payment_success');
$response->setTransactionId($event->data->object->charge);
return $response;
}
浏览网站后,除了post之外,我没有找到任何相关的问题,在那篇文章中我不太明白“你可以将用户的卡片详细信息存储为代币eWAY,然后管理您的应用程序中的日程安排。“,我认为该帖子中的链接也被破坏了。
据我所知,该过程是:首先在Eway上创建令牌客户 - &gt;使用该令牌客户创建再出租客户 - &gt;使用rebill customer创建rebill事件。
我试图给他们发电子邮件,他们说如果你不在AU,我们无法帮助你。现在我真的不知道从哪里开始。也许Eway对每次重复付款都没有沉默的帖子或通知?或者在构建反复出现的biliting事件时我是否遗漏了什么?
由于只允许在SOAP中使用定期计费方法,因此我的代码实际上很长,因此我没有为其他函数附加代码。对不起,我对paymentgateways和PHP一般都很新。