|
| 1 | +<?php |
| 2 | +set_include_path(__DIR__ . '/..'); |
| 3 | + |
| 4 | +require_once "request/merchant/AlipayMerchantRegistrationRequest.php"; |
| 5 | +require_once "model/MerchantRegistrationInfo.php"; |
| 6 | +require_once "model/Logo.php"; |
| 7 | +require_once "model/Address.php"; |
| 8 | +require_once "model/RegistrationDetail.php"; |
| 9 | +require_once "model/Attachment.php"; |
| 10 | +require_once "model/ContactInfo.php"; |
| 11 | +require_once "model/WebSite.php"; |
| 12 | +require_once "model/ProductCodeType.php"; |
| 13 | +require_once "DefaultAlipayClient.php"; |
| 14 | +require_once "request/merchant/AlipayMerchantRegistrationStatusQueryRequest.php"; |
| 15 | +require_once "request/merchant/AlipayMerchantRegistrationInfoQueryRequest.php"; |
| 16 | + |
| 17 | + |
| 18 | +$merchantPrivateKey = file_get_contents(__DIR__ . "/../private-pkcs1.pem"); |
| 19 | + |
| 20 | +$alipayPublicKey = file_get_contents(__DIR__ . "/../public.pem"); |
| 21 | +$alipayClient = new DefaultAlipayClient("https://open-na.alipay.com", $merchantPrivateKey, $alipayPublicKey); |
| 22 | +/** |
| 23 | + * build your clientId |
| 24 | + */ |
| 25 | +$clientId = "T_385XSM502Y108602A"; |
| 26 | +/** |
| 27 | + * build your requestId |
| 28 | + */ |
| 29 | +$registrationRequestId = ""; |
| 30 | +/** |
| 31 | + * build your merchantId |
| 32 | + */ |
| 33 | +$referenceMerchantId = ""; |
| 34 | +/** |
| 35 | + * step1.register merchant |
| 36 | + */ |
| 37 | +$merchantRegistrationRequest = new AlipayMerchantRegistrationRequest(); |
| 38 | +$merchantRegistrationRequest -> setPath("/ams/sandbox/api/v1/merchants/registration"); |
| 39 | +$merchantRegistrationRequest -> setClientId($clientId); |
| 40 | + |
| 41 | +$merchant = new MerchantRegistrationInfo(); |
| 42 | +$merchant -> setMerchantMCC("merchantMCC"); |
| 43 | +$merchant -> setReferenceMerchantId($referenceMerchantId); |
| 44 | +$logo = new Logo(); |
| 45 | +$logo -> setLogoName("logoName"); |
| 46 | +$logo -> setLogoUrl("https://www.logo.com"); |
| 47 | +$merchant -> setLogo($logo); |
| 48 | +$address = new Address(); |
| 49 | +$address -> setAddress1("38 Leighton Road, ****"); |
| 50 | +$address -> setAddress2("40 Leighton Road, ****"); |
| 51 | +$address -> setCity("hong kong"); |
| 52 | +$address -> setLabel("label"); |
| 53 | +$address -> setRegion("HK"); |
| 54 | +$address -> setState("HK"); |
| 55 | +$address -> setZipCode("zipCode"); |
| 56 | +$merchant -> setMerchantAddress($address); |
| 57 | +$merchant -> setMerchantDisplayName("Same_mer"); |
| 58 | +$detail = new RegistrationDetail(); |
| 59 | +$attachment1 = new Attachment(); |
| 60 | +$attachment1 -> setAttachmentName("attachmentName1"); |
| 61 | +$attachment1 -> setAttachmentType("ARTICLES_OF_ASSOCIATION"); |
| 62 | +$attachment1 -> setFile("testFile"); |
| 63 | +$attachment2 = new Attachment(); |
| 64 | +$attachment2 -> setAttachmentName("attachmentName2"); |
| 65 | +$attachment2 -> setAttachmentType("ARTICLES_OF_ASSOCIATION"); |
| 66 | +$attachment2 -> setFile("testFile"); |
| 67 | +$attachments[0] = $attachment1; |
| 68 | +$attachments[1] = $attachment2; |
| 69 | +$detail -> setAttachments($attachments); |
| 70 | + |
| 71 | +$detail -> setBusinessType("ENTERPRISE"); |
| 72 | +$contactInfo = new ContactInfo(); |
| 73 | +$contactInfo -> setContactNo("contactNo123"); |
| 74 | +$contactInfo -> setContactType("MOBILE_PHONE"); |
| 75 | +$contactInfos[0] = $contactInfo; |
| 76 | +$detail -> setContactInfo($contactInfos); |
| 77 | +$detail -> setLegalName("Example Legal Name"); |
| 78 | + |
| 79 | +$registrationAddress = new Address(); |
| 80 | +$registrationAddress -> setRegion("HK"); |
| 81 | + |
| 82 | +$detail -> setRegistrationAddress($registrationAddress); |
| 83 | +$detail -> setRegistrationEffectiveDate("2020-01-01T12:08:55+08:00"); |
| 84 | +$detail -> setRegistrationExpireDate("2020-01-01T12:08:55+08:00"); |
| 85 | +$detail -> setRegistrationNo("registration*****"); |
| 86 | +$detail -> setRegistrationType("ENTERPRISE_REGISTRATION_NO"); |
| 87 | + |
| 88 | +$merchant -> setRegistrationDetail($detail); |
| 89 | +$website = new WebSite(); |
| 90 | +$website -> setDesc("this is webSite desc"); |
| 91 | +$website -> setName("webName"); |
| 92 | +$website -> setUrl("http://www.webSite.com"); |
| 93 | +$websites[0] = $website; |
| 94 | +$merchant -> setWebsites($websites); |
| 95 | + |
| 96 | + |
| 97 | +$merchantRegistrationRequest -> setMerchantInfo($merchant); |
| 98 | +$merchantRegistrationRequest -> setPassThroughInfo("{\"extraInfo\":\"extra\"}"); |
| 99 | +$productCodes[0] = ProductCodeType::CASHIER_PAYMENT; |
| 100 | +$merchantRegistrationRequest -> setProductCodes($productCodes); |
| 101 | +$merchantRegistrationRequest -> setRegistrationNotifyURL("https://merchant/example"); |
| 102 | +$merchantRegistrationRequest -> setRegistrationRequestId($registrationRequestId); |
| 103 | + |
| 104 | + |
| 105 | +$registrationResponse = $alipayClient->execute($merchantRegistrationRequest); |
| 106 | + |
| 107 | +print(json_encode($merchantRegistrationRequest)); |
| 108 | +print('<br>-----------------------------------------------------------------------------<br>'); |
| 109 | +print(json_encode($registrationResponse)); |
| 110 | + |
| 111 | +/** |
| 112 | + * step.2 query registration status |
| 113 | + */ |
| 114 | + |
| 115 | +$registrationStatusQueryRequest = new AlipayMerchantRegistrationStatusQueryRequest(); |
| 116 | +$registrationStatusQueryRequest -> setClientId($clientId); |
| 117 | +$registrationStatusQueryRequest -> setPath("/ams/sandbox/api/v1/merchants/inquiryRegistrationStatus"); |
| 118 | +$registrationStatusQueryRequest -> setRegistrationRequestId($registrationRequestId); |
| 119 | +$registrationStatusResponse = $alipayClient->execute($registrationStatusQueryRequest); |
| 120 | + |
| 121 | +print(json_encode($registrationStatusQueryRequest)); |
| 122 | +print('<br>-----------------------------------------------------------------------------<br>'); |
| 123 | +print(json_encode($registrationStatusResponse)); |
| 124 | + |
| 125 | +/** |
| 126 | + * step3.query merchant registrationInfo |
| 127 | + */ |
| 128 | +$registrationInfoQueryRequest = new AlipayMerchantRegistrationInfoQueryRequest(); |
| 129 | +$registrationInfoQueryRequest -> setClientId($clientId); |
| 130 | +$registrationInfoQueryRequest -> setPath("/ams/sandbox/api/v1/merchants/inquiryRegistrationInfo"); |
| 131 | +$registrationInfoQueryRequest -> setReferenceMerchantId($referenceMerchantId); |
| 132 | + |
| 133 | +$registrationInfoResponse = $alipayClient->execute($registrationInfoQueryRequest); |
| 134 | + |
| 135 | +print(json_encode($registrationInfoQueryRequest)); |
| 136 | +print('<br>-----------------------------------------------------------------------------<br>'); |
| 137 | +print(json_encode($registrationInfoResponse)); |
0 commit comments