albert-finaru/php-card-composer

一系列库,使您能够将NETOPIA支付功能集成到您的网站应用程序和移动应用程序中。

dev-master 2023-09-01 10:29 UTC

This package is not auto-updated.

Last update: 2024-09-28 15:23:51 UTC


README

Parsedown

NETOPIA Payments

NETOPIA Payments Composer

安装

从您的项目根目录运行以下命令

  • composer require netopia/payment

或者

  • 将以下内容添加到您的 composer.json 文件中,如下示例所示

      "require": {
          ...
          "netopia/payment": "^1.0",
          ...
      }
    

    然后从您的终端运行以下命令

    composer install

示例

Laravel中支付请求的一个示例
... use Netopia\Payment\Address; use Netopia\Payment\Invoice; use Netopia\Payment\Request\Card; ... class ExampleController extends Controller { /** * 所有支付请求都将发送到NETOPIA Payments服务器 * SANDBOX : http://sandboxsecure.mobilpay.ro * LIVE : https://secure.mobilpay.ro */ public $paymentUrl; /** * NETOPIA Payments只与证书一起工作。每个NETOPIA合作伙伴(商户)都有一个证书。 * 您可以从管理员面板下载证书。 * 位于Admin -> 商户账户 -> 详情 -> 安全设置 * $x509FilePath变量是您的证书在您平台上的路径 * 例如:/home/certificates/public.cer */ public $x509FilePath; /** * 发票地址 */ public $billingAddress; /** * 配送地址 */ public $shippingAddress; ... public function index() { $this->paymentUrl = 'http://sandboxsecure.mobilpay.ro'; $this->x509FilePath = '/home/certificates/sandbox.XXXX-XXXX-XXXX-XXXX-XXXX.public.cer'; try { $paymentRequest = new Card(); $paymentRequest->signature = 'XXXX-XXXX-XXXX-XXXX-XXXX';//signature - 由mobilpay.ro为每个商户账户生成 $paymentRequest->orderId = md5(uniqid(rand())); // order_id应该是商户账户唯一的 $paymentRequest->confirmUrl = 'https://example.test/card/success'; // mobilPay在支付过程完成后将客户端重定向到此处,是必填项 $paymentRequest->returnUrl = 'https://example.test/ipn';// mobilPay将支付结果发送到此处,是必填项 /* * 发票信息 */ $paymentRequest->invoice = new Invoice(); $paymentRequest->invoice->currency = 'RON'; $paymentRequest->invoice->amount = '20.00'; $paymentRequest->invoice->tokenId = null; $paymentRequest->invoice->details = "通过Composer库支付"; /* * 发票信息 */ $this->billingAddress = new Address(); $this->billingAddress->type = "person"; // 应为 "person" / "company" $this->billingAddress->firstName = "发票姓名"; $this->billingAddress->lastName = "发票姓氏"; $this->billingAddress->address = "Bulevardul Ion Creangă, Nr 00"; $this->billingAddress->email = "test@billing.com"; $this->billingAddress->mobilePhone = "0732123456"; $paymentRequest->invoice->setBillingAddress($this->billingAddress); /* * 配送 */ $this->shippingAddress = new Address(); $this->shippingAddress->type = "person"; // 应为 "person" / "company" $this->shippingAddress->firstName = "配送姓名"; $this->shippingAddress->lastName = "配送姓氏"; $this->shippingAddress->address = "Bulevardul Mihai Eminescu, Nr 00"; $this->shippingAddress->email = "test@shipping.com"; $this->shippingAddress->mobilePhone = "0721234567"; $paymentRequest->invoice->setShippingAddress($this->shippingAddress); /* * 加密 */ $paymentRequest->encrypt($this->x509FilePath); /** * 将以下数据发送到NETOPIA Payments服务器 * 方法:POST * URL:$paymentUrl */ $EnvKey = $paymentRequest->getEnvKey(); $data = $paymentRequest->getEncData(); }catch (\Exception $e) { return "Oops, There is a problem!"; } } ... } 

Laravel中IPN的一个示例

... 使用 Netopia\Payment\Address; 使用 Netopia\Payment\Invoice; 使用 Netopia\Payment\Request\Card; 使用 Netopia\Payment\Request\Notify; 使用 Netopia\Payment\Request\PaymentAbstract; ... class IpnsController extends Controller { ... public $errorCode; public $errorType; public $errorMessage; public $paymentUrl; public $x509FilePath; ... public function index() { ... $this->errorType = PaymentAbstract::CONFIRM_ERROR_TYPE_NONE; $this->errorCode = 0; $this->errorMessage = ''; $this->paymentUrl = 'http://sandboxsecure.mobilpay.ro'; $this->x509FilePath = '/home/certificates/sandbox.XXXX-XXXX-XXXX-XXXX-XXXXprivate.key'; if (strcasecmp($_SERVER['REQUEST_METHOD'], 'post') == 0){ if(isset($_POST['env_key']) && isset($_POST['data'])){ try { $paymentRequestIpn = PaymentAbstract::factoryFromEncrypted($_POST['env_key'],$_POST['data'],$this->x509FilePath); $rrn = $paymentRequestIpn->objPmNotify->rrn; if ($paymentRequestIpn->objPmNotify->errorCode == 0) { switch($paymentRequestIpn->objPmNotify->action){ case 'confirmed': //更新数据库,设置状态为 "confirmed/captured" $this->errorMessage = $paymentRequestIpn->objPmNotify->errorMessage; break; case 'confirmed_pending': //更新数据库,设置状态为 "pending" $this->errorMessage = $paymentRequestIpn->objPmNotify->errorMessage; break; case 'paid_pending': //更新数据库,设置状态为 "pending" $this->errorMessage = $paymentRequestIpn->objPmNotify->errorMessage; break; case 'paid': //更新数据库,设置状态为 "open/preauthorized" $this->errorMessage = $paymentRequestIpn->objPmNotify->errorMessage; break; case 'canceled': //更新数据库,设置状态为 "canceled" $this->errorMessage = $paymentRequestIpn->objPmNotify->errorMessage; break; case 'credit': //更新数据库,设置状态为 "refunded" $this->errorMessage = $paymentRequestIpn->objPmNotify->errorMessage; break; default: $errorType = PaymentAbstract::CONFIRM_ERROR_TYPE_PERMANENT; $this->errorCode = PaymentAbstract::ERROR_CONFIRM_INVALID_ACTION; $this->errorMessage = 'mobilpay_refference_action paramaters is invalid'; } }else{ //更新数据库,设置状态为 "rejected" $this->errorMessage = $paymentRequestIpn->objPmNotify->errorMessage; } }catch (\Exception $e) { $this->errorType = PaymentAbstract::CONFIRM_ERROR_TYPE_TEMPORARY; $this->errorCode = $e->getCode(); $this->errorMessage = $e->getMessage(); } }else{ $this->errorType = PaymentAbstract::CONFIRM_ERROR_TYPE_PERMANENT; $this->errorCode = PaymentAbstract::ERROR_CONFIRM_INVALID_POST_PARAMETERS; $this->errorMessag = 'mobilpay.ro posted invalid parameters'; } } else { $this->errorType = PaymentAbstract::CONFIRM_ERROR_TYPE_PERMANENT; $this->errorCode = PaymentAbstract::ERROR_CONFIRM_INVALID_POST_METHOD; $this->errorMessage = 'invalid request metod for payment confirmation'; } } /** * 与NETOPIA Payments服务器通信 */ header('Content-type: application/xml'); echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"; if($this->errorCode == 0) { echo "<crc>{$this->errorMessage}</crc>"; } else { echo "<crc error_type=\"{$this->errorType}\" error_code=\"{$this->errorCode}\">{$this->errorMessage}</crc>"; } } } 
注释/建议
  • 如果您的平台中存在命名空间问题,您可以寻求服务提供商的帮助解决。例如,在Laravel中,您可以定义一个提供者,将其放入您的vendor目录,然后在composer.json中设置您的命名空间。

  • 如果您的应用程序中任何情况下国家、城市、邮政编码等与地址分开,请将其与地址合并,并创建完整的账单/发货地址。